Batch Find and Replace Text in Multiple Outlook Emails
Hi There Everyone - thanks for this great forum. Alan Chen of DataNumen, suggested I reach out here to find a fix VBA for - "How to Batch Find and Replace Text in Multiple Outlook Emails" - it will not work for me.
Compile Error - User-defined type not defined. Highlights line item - DIM objMailDocument As Word.Document - cannot get beyond that to see if any other errors - appreciate any help. Thanks again.
https://www.datanumen.com/blogs/batc...utlook-emails/
Sub FindReplaceInMultipleEmails()
Dim strFind, strReplace As String
Dim objInspectors As Outlook.Inspectors
Dim objInspector As Outlook.Inspector
Dim objMail As Outlook.MailItem
Dim objMailDocument As Word.Document
'Enter the specific text
strFind = InputBox("Enter the text for find: (Case Sensitive)")
strReplace = InputBox("Enter the text for replacement: (Case Sensitive)")
If Trim(strFind) <> "" Then
Set objInspectors = Outlook.Application.Inspectors
For Each objInspector In objInspectors
If objInspector.CurrentItem.Class = olMail Then
If objInspector.EditorType = olEditorWord Then
Set objMail = objInspector.CurrentItem
Set objMailDocument = objMail.GetInspector.WordEditor
'Find & replace specific text
With objMailDocument.Content.Find
.ClearFormatting
.Text = strFind
.Replacement.ClearFormatting
.Replacement.Text = strReplace
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = True
.MatchWholeWord = False
.Execute Replace:=wdReplaceAll
End With
objMail.Save
End If
End If
Next
MsgBox "Completed!", vbInformation + vbOKOnly
End If
End Sub