How to Batch Replace Different Text with Same One in Your Outlook Email

It is easy to find and replace one text with another in email. But, if you would like to batch replace different text with same text, it is suggested to use the method in this article, which can let you achieve it in bulk.

As we all know, Outlook email uses Text editor. Thus, when it comes to finding and replacing something in email, you can just utilize the “Find and Replace” tool, similar to deals in MS Word. However, this feature only supports you to find and replace one text with another at once. If you hope to batch replace many texts with a same text, you can use the following approach.

Batch Replace Different Text with Same One in Email

  1. At the very outset, launch Outlook program.
  2. Then, press “Alt + F11” to access VBA editor.
  3. Next, in the “Microsoft Visual Basic for Applications” window, add reference to “MS Word Object Library” as per “How to Add an Object Library Reference in VBA“.
  4. After that, put the following code into a blank module.
Sub ReplaceDifferentTextWithSameText()
    Dim objMail As Outlook.MailItem
    Dim objMailInspector As Outlook.Inspector
    Dim objMailDocument As Word.Document
    Dim strFind, strReplacement As String
    Dim varFindArray As Variant
    Dim objMailDocRange As Word.Range
    Dim i As Integer
 
    Set objMail = Outlook.Application.ActiveInspector.CurrentItem
    Set objMailInspector = objMail.GetInspector
    'Turn email into "Edit" mode
    objMailInspector.CommandBars.ExecuteMso ("EditMessage")
    Set objMailDocument = objMailInspector.TextEditor
 
    strFind = InputBox("Enter the texts for find, use " & Chr(34) & ";" & Chr(34) & "to connect the texts:", , "test;example;model")
 
    If strFind <> "" Then
       strReplacement = InputBox("Enter the text for replace:", , "sample")
       If strReplacement <> "" Then
 
          varFindArray = Split(strFind, ";")
 
          'Start replace
          For i = 0 To UBound(varFindArray)
              Set objMailDocRange = objMailDocument.Range
 
              With objMailDocRange.Find
                   .ClearFormatting
                   .Text = varFindArray(i)
                   .Replacement.ClearFormatting
                   .Replacement.Highlight = True
                   .Replacement.Text = strReplacement
                   .Forward = True
                   .Wrap = wdFindContinue
                   .Format = True
                   .MatchCase = False
                   .MatchWholeText = True
                   .MatchWildcards = False
                   .MatchSoundsLike = False
                   .MatchAllTextForms = True
                   .Execute Replace:=wdReplaceAll
             End With
         Next
      End If
    End If
End Sub

VBA Code - Batch Replace Different Text with Same One in Email

  1. Subsequently, add this macro to Quick Access Toolbar or ribbon of Message window, according to the “Optional Step” in “How to Run VBA Code in Your Outlook“.
  2. Eventually, you can have a try.
  • Firstly, open an email.
  • Then, click the macro button.Run Macro in Current Mail
  • Next, you will be required to enter the texts to be found and a specific text for replacement.Specify Texts for Find and Replace
  • After that, when macro completes, all the texts found will be changed to the specific replacement text, like the screenshot below.Different Text Replaced by Same Text

Don’t Be Afraid of Outlook Corruption

When coming across Outlook corruption, generally, most users will get worried. However, if you have made backups for your computer, you can rest easy in that it is considerably simple to recover Outlook data from backups. You can just extract the PST file from the backups without needs to repair the compromised PST file. If you intend to repair it, you can select a powerful enough tool, such as DataNumen Outlook Repair.

Author Introduction:

Shirley Zhang is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including sql repair and outlook repair software products. For more information visit www.datanumen.com

Leave a Reply

Your email address will not be published. Required fields are marked *