Log in

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



areed12
06-13-2016, 07:24 AM
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

gmayor
06-13-2016, 08:56 PM
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

areed12
06-27-2016, 12:58 PM
Thank you so much this worked perfectly!! I really appreciate it!!!