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
 

s.ridd

Board Regular
Joined
Nov 23, 2012
Messages
178
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
 

Forum statistics

Threads
1,082,607
Messages
5,366,593
Members
400,905
Latest member
xcelstudent

Some videos you may like

This Week's Hot Topics

Top