How to catch End of document?

A

alex9128

Hi,

I am writing macros that should go through word document from top to bottom
with
Selection.Next(Unit:=wdParagraph, Count:=1).Select
What condition in Do While should I put to catch end of document?
I mean:
Do While ?condition?
Selection.Next(Unit:=wdParagraph, Count:=1).Select
Loop

Thanks,

Alex
 
M

Mark Tangard

Hi Alex,

In the vast majority of cases the easiest way to code anything
like this is not to move the selection through the document
but to iterate through the paragraphs "collection":

Dim p as Paragraph
For Each p in ActiveDocument.Paragraphs
:
:


This not
only obviates the need to test for the end of the document but
almost always gives you cleaner and faster-running code.
 
M

Mark Tangard

In case it isn't mindblowingly obvious, I hit SEND before I
was totally finished with this reply. There should be a
'Next p' in the below, just after the vertical ellipsis.

MT
 

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