Consulting

Results 1 to 3 of 3

Thread: Programatically insert an attachment, subject line, etc. into an email message

  1. #1

    Programatically insert an attachment, subject line, etc. into an email message

    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

  2. #2
    try changing

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

  3. #3
    Thank you! It works!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •