From: G Teachman on
Hello,

In my current project I have two variables that I initially set:

MaxPages = Selection.Information(wdNumberOfPagesInDocument)
CurPage = Selection.Information(wdActiveEndPageNumber)

These are sent inside a Do Until loop that quits when CurPage = MaxPages.

The first time I ran the macro it ran smoothly just like it was supposed to.
The next time I ran the macro. Nothing happened. It occurred to me that
maybe CurPage and MaxPages were still set and since they are equal the macro
quits. This same behavior happened even after I got out of Word (2007) and
back in again.

What's going on and how can I make sure the variables are not set until the
macro runs?

Thanks,

--
G Teachman
Soil Scientist, USDA-NRCS
From: DaveLett on
Hi,
You can set those variables before the loop, as in the following example.

MaxPages = Selection.Information(wdNumberOfPagesInDocument)
CurPage = Selection.Information(wdActiveEndPageNumber)

Do Until MaxPages = CurPage
Selection.MoveDown unit:=wdParagraph, Count:=1
MaxPages = Selection.Information(wdNumberOfPagesInDocument)
CurPage = Selection.Information(wdActiveEndPageNumber)
Loop


HTH,
Dave

"G Teachman" wrote:

> Hello,
>
> In my current project I have two variables that I initially set:
>
> MaxPages = Selection.Information(wdNumberOfPagesInDocument)
> CurPage = Selection.Information(wdActiveEndPageNumber)
>
> These are sent inside a Do Until loop that quits when CurPage = MaxPages.
>
> The first time I ran the macro it ran smoothly just like it was supposed to.
> The next time I ran the macro. Nothing happened. It occurred to me that
> maybe CurPage and MaxPages were still set and since they are equal the macro
> quits. This same behavior happened even after I got out of Word (2007) and
> back in again.
>
> What's going on and how can I make sure the variables are not set until the
> macro runs?
>
> Thanks,
>
> --
> G Teachman
> Soil Scientist, USDA-NRCS