OutlookVBA for finding and replacing the text from original email

rkvalu

New member
Local time
Today, 04:41
Joined
Sep 7, 2016
Messages
1
I am trying to run outlook VBA to find and replace text from original email to new email to bunch of stakeholders. Finding difficulty to run the script.
Scenario, I get an email which has Company Name list. So whenever I am running this script it should replace with company name listed on the original email. Below is my script.

Sub Test()

Dim origEmail As MailItem

Dim replyEmail As MailItem

Dim oRespond As Outlook.MailItem

Dim strcompany As String

Dim strHTML As String

Set origEmail = Application.ActiveWindow.Selection.Item(1)

Set replyEmail = Application.CreateItemFromTemplate("C:\Users\test-.oft")

strcompany = InputBox("Issue : ", "Replace %company%")

strHTML = Replace(replyEmail.HTMLBody, "Company:", strissue)

replyEmail.HTMLBody = replyEmail.HTMLBody & origEmail.Reply.HTMLBody

replyEmail.Subject = replyEmail.Subject & origEmail.Reply.Subject

replyEmail.Display

End Sub
 
Where is strcompany in
Code:
strcompany = InputBox("Issue : ", "Replace %company%")

used? And where is strissue in

Code:
strHTML = Replace(replyEmail.HTMLBody, "Company:", strissue)

coming from? I suggest you put Option Explicit at the top of your modules so that your are force to declare variables. That helps avoid problems with typos.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom