Insert total page numbers

J

Jens

I want to add the page number an the total numbers of pages in the header.
I use this syntax to add to pagenumber:

..ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).PageNumbers.Add(PageNumberAlignment:=wdAlignPageNumberRight, FirstPage:=False)

but can't figure out how the add total number of pages.
Like page 1 of 12

Thx
Jens
 
J

Jonathan West

Jens said:
I want to add the page number an the total numbers of pages in the header.
I use this syntax to add to pagenumber:

.ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).PageNumbers.Add(PageNumberAlignment:=wdAlignPageNumberRight,
FirstPage:=False)

but can't figure out how the add total number of pages.
Like page 1 of 12

Thx
Jens

Use a NUMPAGES field


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jens

Use a NUMPAGES field


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
Jonathan

In the past I used early binding to word8, but now some clients with XP
machines and many different language versions, I started get problems, and
what I understand from several newsgroups, that late binding is more flexible
in this kind of scenario.
In the past I used this code:
..Selection.Fields.Add(Range:=.Selection.Range, Type:=wdFieldNumPages)

Could you be kind and show me a sample code how to use NUMPAGES?

Jens
 
J

Jonathan West

Jens said:
Jonathan

In the past I used early binding to word8, but now some clients with XP
machines and many different language versions, I started get problems, and
what I understand from several newsgroups, that late binding is more
flexible
in this kind of scenario.
In the past I used this code:
.Selection.Fields.Add(Range:=.Selection.Range, Type:=wdFieldNumPages)

Could you be kind and show me a sample code how to use NUMPAGES?


You don't need to use code at all. If you include a NUMPAGES field in the
template, it will automatically update to show the total number of pages in
any document based on the template.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jens

You don't need to use code at all. If you include a NUMPAGES field in the
template, it will automatically update to show the total number of pages in
any document based on the template.

--
I am not able to use a special designed template with a pre inserted field,
as users are spread all over the world, with an unknown numbers of formats
and versions. So I can only use the local Normal.dot template, and start from
schratch.
Regards
Jens
 
J

Jonathan West

Jens said:
I am not able to use a special designed template with a pre inserted
field,
as users are spread all over the world, with an unknown numbers of formats
and versions. So I can only use the local Normal.dot template, and start
from
schratch.
Regards
Jens

OK, If you are using late binding, then the only change you need make to the
line of code you had before is to substitute the value of wdFieldNumPages
for the constant itself. This constant has the value 26.

By the way, I would be very surprised if it really is impossible to
distribute a template as part of your application. Since you have no idea
what kinds of mess users may have made of their normal.dot, distributing
yourown template would probably increase the stability of your application

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 

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