how to make empty all words with a specific pattern

T

Tony

Dear Experts,

I have a word document (actually a template) where I would like to
remove all the words with a prefix "$DOC$" (actually indicating an
unused tag). My first desired step is to look for these words and
replace them with an empty string. Some of these words are inside
tables. Could any one show me how to achieve it programmatically?
Any hint is a big help. Thank you in advance.

Tony
 
D

dedawson

No VBA required. Search and Replace using Wildcards

Search string = ($DOC$)([! ]{1,255})

Replace string = null or space

note: be sure you have [! ] not [!]
 
T

Tony

Hi dedawson,

Thank you for the reply. I do need a piece of code in VBA (the best
in VC++). It is part of an existing software package. Any further
instruction is much appreciated.

Tony
 
D

dedawson

Sub aaa()
Selection.Find.ClearFormatting
Selection.Find.Replacement.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.HomeKey Unit:=wdStory
Selection.Find.Text = "($DOC$)([! ]{1,255})"
Selection.Find.Replacement.Text = ""
Selection.Find.Execute Replace:=wdReplaceAll
Selection.Find.MatchWildcards = False
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top