【问题标题】:How to attach file in open email?如何在打开的电子邮件中附加文件?
【发布时间】:2021-10-03 14:51:37
【问题描述】:

我想在打开的电子邮件中添加附件。

Sub AddAttachment() 
    Dim myItem As Outlook.MailItem 
    Dim myAttachments As Outlook.Attachments 
    'Set myItem = Application.CreateItem(olMailItem) 'this will create a new Email which I don't want
    Set myItem= thisEmail **I need help with this part**
    Set myAttachments = myItem.Attachments 
    myAttachments.Add "D:\Documents\Q496.xlsx", olByValue, 1, "4th Quarter 1996 Results Chart" 
    myItem.Display 
End Sub

【问题讨论】:

    标签: vba outlook attachment


    【解决方案1】:

    如果邮件项目在检查器窗口中打开,您可以使用Inspector.CurrentItem 属性检索邮件项目。

    Sub AddAttachment() 
         Dim myItem As Outlook.MailItem 
         Dim myAttachments As Outlook.Attachments 
         'Set myItem = Application.CreateItem(olMailItem) 'this will create a new Email which I don't want
         Set myItem= Application.ActiveInspector.CurrentItem
         Set myAttachments = myItem.Attachments 
         myAttachments.Add "D:\Documents\Q496.xlsx", olByValue, 1, "4th Quarter 1996 Results Chart" 
         myItem.Display 
       End Sub
    

    如果在Explorer 窗口中选择了邮件项目,您需要使用Selection 对象来检索文件夹视图中当前选择的项目:

    Sub AddAttachment() 
         Dim myItem As Outlook.MailItem 
         Dim myAttachments As Outlook.Attachments 
         'Set myItem = Application.CreateItem(olMailItem) 'this will create a new Email which I don't want
         Set myItem= Application.ActiveExplorer.Selection.Item(1)
         Set myAttachments = myItem.Attachments 
         myAttachments.Add "D:\Documents\Q496.xlsx", olByValue, 1, "4th Quarter 1996 Results Chart" 
         myItem.Display 
       End Sub
    

    【讨论】:

    • 如果用户正在编辑内联回复,ActiveExplorer.Selection.Item(1) 行必须替换为Set myItem= Application.ActiveExplorer.ActiveInlineResponse
    猜你喜欢
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-25
    • 1970-01-01
    • 2011-12-04
    • 1970-01-01
    相关资源
    最近更新 更多