Find and Replace Macro

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am trying to create a macro to find text that has been struckthrough and
replace it with text that is still struckthrough but hidden.

When I use the macro recorder this is what I get (the find and replace
command works great but the macro does not do anything):

Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub

From what I can tell I need to insert something in between the quotes but am
not sure what to insert. I am using Word 2002.

Thanks,
David
 
David,

You don't need a macro for this, but here is one that should work:
Sub ScrathcMacro()
Dim rngstory As Word.Range
Set rngstory = ActiveDocument.Range
With rngstory.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = False
.MatchWholeWord = True
.Wrap = wdFindContinue
.Text = ""
.Font.StrikeThrough = True
With .Replacement
.Text = ""
.Font.Bold = True
.Font.Hidden = True
End With
.Execute Replace:=wdReplaceAll
End With
End Sub
 
Thanks very much for the macro. It is still not doing exactly what I want
though. It replaces the text but not other characters like periods, commas
etc. It also leaves the strikethroughs visible (while at the same time
turning the text to hidden and adding another strikethrough that is hidden, I
think). Any more help you can provide would greatly be appreciated.

I know I don't need the macro but I have to perform this task on many
different documents and would prefer to not have to go throught the find and
replace process for each one. Unless you know of an easier way to do it? I
am still a novice with Word.

David Ayers
 
David,

Yes I see what you mean. This isn't tested extensively (like the last), but
try:

Sub ScrathcMacro()
Dim rngstory As Word.Range
Set rngstory = ActiveDocument.Range
With rngstory.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = True
.MatchWholeWord = True
.Wrap = wdFindContinue
.Text = "*"
.Font.StrikeThrough = True
With .Replacement
.Text = "^&"
.Font.Bold = True
.Font.Hidden = True
End With
.Execute Replace:=wdReplaceAll
End With
End Sub
 
Thanks again,

I had to tweak it a little this is what I have and it works!

Sub ScrathcMacro()
Dim rngstory As Word.Range
Set rngstory = ActiveDocument.Range
With rngstory.Find
.ClearFormatting
.Replacement.ClearFormatting
.MatchWildcards = True
.MatchWholeWord = True
.Wrap = wdFindContinue
.Text = ""
.Font.StrikeThrough = True
With .Replacement
.Text = "^&"
.Font.Hidden = True
End With
.Execute Replace:=wdReplaceAll
End With
End Sub

One more question though, is there a way to make it hide tables that have
all cells struckthrough? This is not a deal breaker but just a convenience.

Thanks again,
David
 
Back
Top