Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to make empty all words with a specific pattern

3 views
Skip to first unread message

Tony

unread,
Jun 3, 2011, 3:46:33 PM6/3/11
to
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

dedawson

unread,
Jun 3, 2011, 4:52:07 PM6/3/11
to
No VBA required. Search and Replace using Wildcards

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

Replace string = null or space

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

Tony

unread,
Jun 3, 2011, 7:07:25 PM6/3/11
to
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

dedawson

unread,
Jun 3, 2011, 9:22:01 PM6/3/11
to
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

0 new messages