如何在打开的电子邮件中附加文件?



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

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:DocumentsQ496.xlsx", olByValue, 1, "4th Quarter 1996 Results Chart" 
myItem.Display 
End Sub

您可以使用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:DocumentsQ496.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:DocumentsQ496.xlsx", olByValue, 1, "4th Quarter 1996 Results Chart" 
myItem.Display 
End Sub

相关内容

  • 没有找到相关文章

最新更新