Hi all,
I would like to create a macro for use in outlook. It’s very straightforward, all I need to is to run a search and replace for several keywords on the open email. I’ve found some VBA code which does the job in Word (with some tweaking to run multiple searches obviously), but I’m struggling to find a tutorial with how I can link this to outlook. Here’s what I found so far:
Now the stuff within the loop is fine and does the search and replace, but I need to change all the bits beforehand to link to the open outlook message, rather than a word doc. The trouble I’m having is that all the tutorials are more complicated than what I need, they open multiple messages/folders, or run the macro when the email is sent, or when the email arrives in the inbox for example.
Anyone know of a bog-basic way to run the macro just on the active message?
Thanks for any help.
I would like to create a macro for use in outlook. It’s very straightforward, all I need to is to run a search and replace for several keywords on the open email. I’ve found some VBA code which does the job in Word (with some tweaking to run multiple searches obviously), but I’m struggling to find a tutorial with how I can link this to outlook. Here’s what I found so far:
Code:
Dim oWord As Word.Application
Dim oDoc As Word.Document
Set oWord = GetObject(, "Word.Application")
If oWord Is Nothing Then
Set oWord = CreateObject("Word.Application")
End If
oWord.Documents.Open FileName:="C:\Users\mp\Desktop\test.doc"
oWord.Documents("test.doc").Activate
Set oDoc = oWord.ActiveDocument
' Loop until no more items are found.
Do
oWord.Selection.Find.ClearFormatting
With oWord.Selection.Find
.Text = "XXX"
.Execute ReplaceWith:="YYY", _
Replace:=wdReplaceAll, Forward:=True
End With
' Exit the loop when the search is unsuccessful.
If oWord.Selection.Find.Execute = False Then Exit Do
Loop
Now the stuff within the loop is fine and does the search and replace, but I need to change all the bits beforehand to link to the open outlook message, rather than a word doc. The trouble I’m having is that all the tutorials are more complicated than what I need, they open multiple messages/folders, or run the macro when the email is sent, or when the email arrives in the inbox for example.
Anyone know of a bog-basic way to run the macro just on the active message?
Thanks for any help.