Looping through a document

J

Jack B. Pollack

I have some experience with Visual Basic, but have never worked with VBA. I
am trying to write a program that will loop through a Word document and look
for imbedded tags eg :
1/ this is some tagged text /1
/2 other tagged text /2

When it finds the tags I want to change the tagged text to a particular
font.

Can someone help me get started with this? I am not even sure how to refer
to the document object an loop through it.

Thanks
 
D

Doug Robbins - Word MVP

Hi Jack,

See the article “Finding and replacing characters using wildcards” at:

http://www.mvps.org/word/FAQs/General/UsingWildcards.htm

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
G

Graham Mayor

The looping can be achieved as follows:

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="(\/[0-9])(*)\1", _
MatchWildcards:=True, ReplaceWith:="\2", _
Wrap:=wdFindContinue, Forward:=True) = True
With Selection.Range.Font
.Name = "Arial"
.Bold = True
.Color = wdColorBlue
End With
Loop
End With

where your tags are removed and the text they contain is changed to Arial
bold coloured blue.

--
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
Graham Mayor - Word MVP
E-mail (e-mail address removed)
Web site www.gmayor.dsl.pipex.com
Word MVP web site www.mvps.org/word
<>>< ><<> ><<> <>>< ><<> <>>< <>>< ><<>
 

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