0

I want to add an attachment in open email.

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 

1 Answer 1

1

You can use the Inspector.CurrentItem property for retrieving a mail item if it is opened in the inspector window.

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 

If the mail item is selected in the Explorer window you need to use the Selection object for retrieving the currently selected item in the folder view:

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 
Sign up to request clarification or add additional context in comments.

1 Comment

If the user is editing an inline reply, the ActiveExplorer.Selection.Item(1) line must be replaced with Set myItem= Application.ActiveExplorer.ActiveInlineResponse

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.