Consulting

Results 1 to 3 of 3

Thread: Outlook 2016-Pull Body Text from email when I click reply and insert in Body

  1. #1
    VBAX Newbie
    Joined
    Jun 2016
    Posts
    2
    Location

    Outlook 2016-Pull Body Text from email when I click reply and insert in Body

    Good Morning, I am trying to write a simple script where when I click the reply button in Outlook it pulls specific text from the email I am replying from and puts it in to the body of my reply email. I want it to pull all of the text beginning from the words "Appointment Manager" and end at the word "Company Website". I don't have much experience writing script in Outlook so I'm sort of at a loss, so any help would be greatly appreciated.

    So for example if I received an email that looked this (below), I would want to pull all of the text in red in to my reply email every time I clicked reply.

    Dear, Name.

    Random body text etc. etc.

    Sincerely,

    Name
    "Appointment Manager

    Company
    123 Address
    City, State Zip

    Contact Info
    Phone: 999-999-9999
    Fax:
    Company Website

  2. #2
    If that text actually exists in the message, the following macro will create a reply and put that text in the body of the reply before the default signature associated with the sending account.

    Option Explicit
    
    Sub Example()
    Dim olMsg As MailItem
    Dim olReply As MailItem
    Dim olInsp As Outlook.Inspector
    Dim wdDoc As Object
    Dim oRng As Object, oStart As Object
    
        On Error Resume Next
        Set olMsg = ActiveExplorer.Selection.Item(1)
        Set olReply = olMsg.Reply
        With olReply
            Set olInsp = .GetInspector
            Set wdDoc = olInsp.WordEditor
            Set oStart = wdDoc.Range(0, 0)
            Set oRng = wdDoc.Range
            .Display
            With oRng.Find
                Do While .Execute(findText:="Appointment Manager")
                    oRng.End = wdDoc.Range.End
                    oRng.End = oRng.start + InStr(oRng, "Company Website")
                    oRng.End = oRng.Paragraphs.last.Range.End - 1
                    oStart.Text = oRng.Text
                    'Or if you want the formatting of the original
                    'oStart.FormattedText = oRng.FormattedText
                    oStart.collapse 0
                    oStart.Select
                    Exit Do
                Loop
            End With
        End With
    lbl_Exit:
        Set olMsg = Nothing
        Set olReply = Nothing
        Set olInsp = Nothing
        Set wdDoc = Nothing
        Set oRng = Nothing
        Set oStart = Nothing
        Exit Sub
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.com

  3. #3
    VBAX Newbie
    Joined
    Jun 2016
    Posts
    2
    Location
    Thank you so much this worked perfectly!! 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
  •