Change Word Macro to work in Outlook 2007

explorer

New Member
Joined
Mar 22, 2012
Messages
11
For each reply in Outlook, I need to remove the text in the body of the message starting with the word "From" through the word "Support." I recorded the Macro in Word but I can't get it to work in Outlook. I also need to delete the information appearing between the two forward slashes that appear in the body of the message (in only the first instance.) and leave one in its place. Can anyone help me amend the code below to get this to work? Thank you in advance!

Sub Clean()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "From:*support"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "/*/"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.Execute
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="/"
End Sub

Looking online I thought the following code might do the trick, however, I am still having issues...


Sub Clean()
Dim objDoc As Word.Document
Dim objWord As Word.Application
Dim objRange As Word.Range
Set objDoc = ActiveInspector.WordEditor
Set objWord = objDoc.Application
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "From:*support"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "/*/"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.Find.Execute
Selection.Find.Execute
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="/"
End Sub
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You could try something like the code below.

Code:
Sub Clean()

Dim objDoc As Word.Document
Dim objWord As Word.Application
Dim objSel As Word.Selection


    Set objDoc = ActiveInspector.WordEditor
    Set objWord = objDoc.Application
    Set objSel = objWord.Selection
    
    objSel.Goto What:=wdGoToSection, Which:=wdGoToFirst
    objSel.Find.Execute FindText:="From:*support", MatchWildcards:=True, Forward:=True, ReplaceWith:=""
    objSel.Goto What:=wdGoToSection, Which:=wdGoToFirst
    objSel.Find.Execute FindText:="/*/", MatchWildcards:=True, Forward:=True, ReplaceWith:="/"
    
End Sub

This will remove the first and only the first instance of the text you're searching for and replace it accordingly.

Hope this helps

Simon
 
Upvote 0

Forum statistics

Threads
1,214,899
Messages
6,122,155
Members
449,068
Latest member
shiz11713

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top