我想将当前选定的电子邮件链接到活动Excel工作表的选定单元格。
显示错误:
对象不支持此属性或方法
指向:
rngSelection.Value = olItem.GetInspector.URL
Outlook代码:
Sub CopyLinkToSelectedEmail()
Declare all variables
Dim olItem As Object
Dim xlApp As Excel.Application
Dim xlWorkbook As Excel.Workbook
Dim xlWorksheet As Excel.Worksheet
Dim rngSelection As Excel.Range
' Get the currently selected item(email) in Outlook
Set olItem = Outlook.Application.ActiveExplorer.Selection(1)
' Check the type of the selected item
Select Case TypeName(olItem)
Case "MailItem"
' Get the active Excel workbook and worksheet
Set xlApp = GetObject(, "Excel.Application")
Set xlWorkbook = xlApp.ActiveWorkbook
Set xlWorksheet = xlWorkbook.ActiveSheet
' Get the currently selected cell in the excel worksheet
Set rngSelection = xlApp.Selection
' Check the type of the selected cell
If TypeName(rngSelection) = "Range" Then
' Copy the link to the email to the selected worksheet cell
rngSelection.Value = olItem.GetInspector.URL
Else
' Display a message if the selected cell is not a valid range
MsgBox "A valid cell must be selected in the Excel worksheet to run this code.", vbOKOnly + vbExclamation
End If
Case Else
' Display a message and exit the macro if the selected item is not a mail item
MsgBox "An email mail item must be selected to run this macro.", vbOKOnly + vbExclamation
Exit Sub
End Select
End Sub
1条答案
按热度按时间vsnjm48y1#
在下面的代码行中:
Inspector类不提供
URL
属性。如果您需要在Outlook中唯一标识项目,则可以使用Inspector.CurrentItem属性获取Outlook项目示例,该属性返回表示检查器中显示的当前项目的对象。然后可以使用属性和方法来标识项。如果您只在计算机上处理一个帐户,那么您可以考虑使用
EntryID
属性。但更好的方法是引入您自己的ID,该ID可以存储在用户属性中,请参阅PropertyAccessor,它允许获取和设置未在Outlook对象模型中显式公开的项级属性