How to tell when you are at the end of the Word document

D

dstanger

I'm writing some code to go through a document to find some text, cursor down
to the table below the text, select the table and delete it's contents. Then
continue on doing the same thing until the end of the document. My question
is how can you tell when you've reach the end of the document to break out of
the loop?

Thanks, dstanger
 
D

Doug Robbins

Use Do While . Execute() = True

as in

' Macro to round all numbers in a document

' Macro created 19/7/00 by Doug Robbins

'

Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(FindText:="[0-9]{1,}.[0-9]{3,}", MatchWildcards: =
True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Range.Text = Round(Selection.Range.Text, 2)
Loop
End With

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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