N
Neil Fraser
Hello,
A scripted search and replace in a Word document works fine when
replacing text with other text. But it doesn't do anything when
replacing text with an empty string.
With WordDoc.Selection.Find
.ClearFormatting
.Replacement.Font.ColorIndex = wdAuto
.Replacement.Font.Bold = False
.Text = "test"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.MatchFuzzy = False
.Execute Replace:=wdReplaceAll
End With
Change
.Replacement.Text = ""
to
.Replacement.Text = " "
and it will replace "test" with a space perfectly. But there doesn't
seem to be a way to replace "test" with nothing. Any suggestions on
how to delete text?
A scripted search and replace in a Word document works fine when
replacing text with other text. But it doesn't do anything when
replacing text with an empty string.
With WordDoc.Selection.Find
.ClearFormatting
.Replacement.Font.ColorIndex = wdAuto
.Replacement.Font.Bold = False
.Text = "test"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
.MatchFuzzy = False
.Execute Replace:=wdReplaceAll
End With
Change
.Replacement.Text = ""
to
.Replacement.Text = " "
and it will replace "test" with a space perfectly. But there doesn't
seem to be a way to replace "test" with nothing. Any suggestions on
how to delete text?