I am building complex documents that need Page X of Y in the footer, and
this is happening all in VBA. I am combining documents in code, and cannot
have the pagenum and numpages fields linked when the document is completed,
because it is combined with other documents. So I will get a final document
and need to write my own page numbers in the footer. Every page will be in
its own section and linktoprevious will always be false. I do not see a
Pages collection to loop through. Does anybody have a sample of how I might
do this? Use bookmarks perhaps? I just want to loop from page to page and
fill in the bookmark with Page X of Y. Please help!

Derek

Re: PageNum and NumPages by Jay

Jay
Tue Jun 26 15:21:58 CDT 2007

Since every page is its own section, loop through the document's Sections
collection. Something like this:

Sub demo()
Dim oSec As Section
Dim SecNum As Long
Dim SecCount As Long

SecCount = ActiveDocument.Sections.Count

For SecNum = 1 To SecCount
Set oSec = ActiveDocument.Sections(SecNum)
oSec.Footers(wdHeaderFooterPrimary).Range.Text _
= "Page " & SecNum & " of " & SecCount
Next
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

Derek Hart wrote:
> I am building complex documents that need Page X of Y in the footer,
> and this is happening all in VBA. I am combining documents in code,
> and cannot have the pagenum and numpages fields linked when the
> document is completed, because it is combined with other documents. So I
> will get a final document and need to write my own page numbers
> in the footer. Every page will be in its own section and
> linktoprevious will always be false. I do not see a Pages collection
> to loop through. Does anybody have a sample of how I might do this? Use
> bookmarks perhaps? I just want to loop from page to page and
> fill in the bookmark with Page X of Y. Please help!
> Derek



Re: PageNum and NumPages by Derek

Derek
Tue Jun 26 15:55:49 CDT 2007

I might have more sections than just one per page... lots of columns... how
can I do this per page?

Derek

"Jay Freedman" <jay.freedman@verizon.net> wrote in message
news:u7Yxm%23CuHHA.292@TK2MSFTNGP02.phx.gbl...
> Since every page is its own section, loop through the document's Sections
> collection. Something like this:
>
> Sub demo()
> Dim oSec As Section
> Dim SecNum As Long
> Dim SecCount As Long
>
> SecCount = ActiveDocument.Sections.Count
>
> For SecNum = 1 To SecCount
> Set oSec = ActiveDocument.Sections(SecNum)
> oSec.Footers(wdHeaderFooterPrimary).Range.Text _
> = "Page " & SecNum & " of " & SecCount
> Next
> End Sub
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup
> so all may benefit.
>
> Derek Hart wrote:
>> I am building complex documents that need Page X of Y in the footer,
>> and this is happening all in VBA. I am combining documents in code,
>> and cannot have the pagenum and numpages fields linked when the
>> document is completed, because it is combined with other documents. So I
>> will get a final document and need to write my own page numbers
>> in the footer. Every page will be in its own section and
>> linktoprevious will always be false. I do not see a Pages collection
>> to loop through. Does anybody have a sample of how I might do this? Use
>> bookmarks perhaps? I just want to loop from page to page and
>> fill in the bookmark with Page X of Y. Please help!
>> Derek
>
>



Re: PageNum and NumPages by Jay

Jay
Tue Jun 26 19:53:03 CDT 2007

Why can't your macro just stick an ordinary Page {PAGE} of {NUMPAGES}
in the footer of the combined document? There's no reason the fields
should need to link back to the source documents.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

On Tue, 26 Jun 2007 13:55:49 -0700, "Derek Hart"
<derekmhart@yahoo.com> wrote:

>I might have more sections than just one per page... lots of columns... how
>can I do this per page?
>
>Derek
>
>"Jay Freedman" <jay.freedman@verizon.net> wrote in message
>news:u7Yxm%23CuHHA.292@TK2MSFTNGP02.phx.gbl...
>> Since every page is its own section, loop through the document's Sections
>> collection. Something like this:
>>
>> Sub demo()
>> Dim oSec As Section
>> Dim SecNum As Long
>> Dim SecCount As Long
>>
>> SecCount = ActiveDocument.Sections.Count
>>
>> For SecNum = 1 To SecCount
>> Set oSec = ActiveDocument.Sections(SecNum)
>> oSec.Footers(wdHeaderFooterPrimary).Range.Text _
>> = "Page " & SecNum & " of " & SecCount
>> Next
>> End Sub
>>
>> --
>> Regards,
>> Jay Freedman
>> Microsoft Word MVP FAQ: http://word.mvps.org
>> Email cannot be acknowledged; please post all follow-ups to the newsgroup
>> so all may benefit.
>>
>> Derek Hart wrote:
>>> I am building complex documents that need Page X of Y in the footer,
>>> and this is happening all in VBA. I am combining documents in code,
>>> and cannot have the pagenum and numpages fields linked when the
>>> document is completed, because it is combined with other documents. So I
>>> will get a final document and need to write my own page numbers
>>> in the footer. Every page will be in its own section and
>>> linktoprevious will always be false. I do not see a Pages collection
>>> to loop through. Does anybody have a sample of how I might do this? Use
>>> bookmarks perhaps? I just want to loop from page to page and
>>> fill in the bookmark with Page X of Y. Please help!
>>> Derek
>>
>>
>