我有以下代码,它将在关联程序中打开附件。我正在尝试设置一条规则,它将从某个电子邮件地址运行。问题是当我选择运行此脚本时,它没有列出。
Sub OpenAttachmentInNativeApp()
' based on code posted by Sue Mosher
' http://tinyurl.com/684zg4
Dim myShell As Object
Dim MyItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
Dim i As Long
Dim Att As String
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set MyItem = ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set MyItem = ActiveInspector.CurrentItem
Case Else
End Select
On Error GoTo 0
If MyItem Is Nothing Then
GoTo ExitProc
End If
Set myAttachments = MyItem.Attachments
' Windows Script Host Object
Set myShell = CreateObject("WScript.Shell")
If myAttachments.Count > 0 Then
For i = 1 To myAttachments.Count
Att = myAttachments.Item(i).DisplayName
' delete just in case it exists from before
On Error Resume Next
Kill "C:\" & Att
On Error GoTo 0
myAttachments.Item(i).SaveAsFile "C:\" & Att
myShell.Run "C:\" & Att
Next i
End If
ExitProc:
Set myAttachments = Nothing
Set MyItem = Nothing
Set myShell = Nothing
End Sub
答案1
尝试
Sub OpenAttachmentInNativeApp(MyItem 作为 MailItem)