PDA

View Full Version : [SOLVED:] Programatically insert an attachment, subject line, etc. into an email message



acantor
03-09-2014, 10:09 AM
I have a macro that inserts a particular attachment (plus subject line and boilerplate body text) into an Outlook message. It works exactly as I want when I trigger the macro from an Outlook main page (e.g., the Inbox); but when I activate it from within a message that I am composing, the macro creates a new message.

Is there a way to modify the code so the magic happens within the message I am composing? I am willing to lose the ability to trigger the macro from the Inbox.



Sub AddAttachment()
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments

Dim AttachmentName, BodyText, SubjectText As String

Let AttachmentName = "c:\test.pdf"
Let BodyText = "Thank you for writing. The attachment contains a full explanation."
Let SubjectText = "Reply to your Question."

Set myItem = Application.CreateItem(olMailItem)
Set myAttachments = myItem.Attachments
myAttachments.Add AttachmentName
myItem.Subject = SubjectText
myItem.Body = BodyText
myItem.Display
End Sub

westconn1
03-09-2014, 04:03 PM
try changing


' Set myItem = Application.CreateItem(olMailItem)
Set myItem = ActiveInspector.CurrentItem

acantor
03-09-2014, 05:51 PM
Thank you! It works!