Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Aug 2016
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Outlook VBA Help

    I am looking for VBA script to attach to an icon in a ribbon bar. This icon will run the script which will do the following:
    1. Forward the selected email as an attachment to a single address.
    2. Subject of new email will be subject of attached email.
    3. A body sentence which states a single line.

    The idea is for someone to take a suspicious email/spam/et al, select it, then click the icon in the ribbon to forward that selected email as an attachment to a single address.

    I appreciate your help on this.

  2. #2
    Star Lounger Graham Mayor's Avatar
    Join Date
    Mar 2016
    Location
    Cyprus
    Posts
    69
    Thanks
    0
    Thanked 24 Times in 24 Posts
    The following code will do that
    Code:
    Option Explicit
    
    Sub ForwardAsAttachment()
    Dim olItem As MailItem
    Dim olMail As MailItem
    Dim olInsp As Outlook.Inspector
    Dim wdDoc As Object
    Dim oRng As Object
    Const strText As String = "This is the text that you want in the body of your message"
    
        On Error GoTo lbl_Exit
        Set olItem = ActiveExplorer.Selection.Item(1)
        Set olMail = CreateItem(olMailItem)
        With olMail
            .subject = olItem.subject
            .To = "someone@somewhere.com" 'the address you wish to send it to
            .Attachments.Add olItem
            .Display 'Do not remove this line or the next lines will not work
            Set olInsp = .GetInspector
            Set wdDoc = olInsp.WordEditor
            Set oRng = wdDoc.Range(0, 0)
            oRng.Text = strText
            '.Send 'remove the leading apostrophe after testing
        End With
    lbl_Exit:
        Set olItem = Nothing
        Set olMail = Nothing
        Set olInsp = Nothing
        Set wdDoc = Nothing
        Set oRng = Nothing
        Exit Sub
    End Sub
    Graham Mayor - Word MVP
    http://www.gmayor.com

  3. #3
    New Lounger
    Join Date
    Aug 2016
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you for your assistance on this. I really appreciate it.

Posting Permissions

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