Word page x of y in footer issue

L

lorraine

Hello I'm using automation to generate a word document on the client's
computer.

In the document I included in the footer's text range some words I want
shown in there, but I also want to show the page number in "Page X of
Y" format. However I've only come across the Add method for PageNumbers
which is simply the current page's number and which also overwrites the
text I had in the footer.

Is there a way to include both my custom text and the page number in
the page x of y format in the footer through automation? I tried
recording a macro, but it didn't catch any of my actions.

Thanks for any help
Lorraine
 
J

Jonathan West

lorraine said:
Hello I'm using automation to generate a word document on the client's
computer.

In the document I included in the footer's text range some words I want
shown in there, but I also want to show the page number in "Page X of
Y" format. However I've only come across the Add method for PageNumbers
which is simply the current page's number and which also overwrites the
text I had in the footer.

Is there a way to include both my custom text and the page number in
the page x of y format in the footer through automation? I tried
recording a macro, but it didn't catch any of my actions.

Thanks for any help
Lorraine

Hi Lorraine

page numbers are done my using the PAGE field and NUMPAGES field. You need
to insert these fields into the footer. You can do this using the Fields.Add
method, or alternatively, you could do this manually, create an AutoText
entry covering the fields, and then in individual documents use the
AutoTextEntries("name").Insert method


--
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
 
L

lorraine

Thank you for the tip. I now can get the page number and the number of
pages individually, but I can't seem to piece them together. I'm not
use to adding fields so maybe I'm doing it wrong, but whenever I add
the field for wdFieldPage (33) and then wdFieldNumPages (26) they end
up overwriting each other.

oDoc.Fields.Add oDoc.Sections(1).Footers(1).Range, 33 ' 33 -
wdFieldPage
oDoc.Fields.Add oDoc.Sections(1).Footers(1).Range, 26 ' 26 -
wdFieldNumPages

(everything is in vbscript)

Plus I'm not exactly sure how to add the word "Page " and " of ".

A behavior I noticed is that if I place the Field.Add code after my
custom footer text.

With oDoc.Sections(1)
With .Footers(1).Range
.Font.Size = 8
.Text = .Text & "some custom footer text here"
.Paragraphs.Alignment = 1
End With
End With

the Page number is accurately reflected, but it overwrites my footer
text -- it doesn't add so much as replace.

However if I place the Fields.Add code anywhere before writing to the
footer, my footer text is kept, but the page number doesn't seem to be
linked to the overall document. It constantly prints "1" and when I
look into the footer section of the word document, it's just regular
text rather than a special object.

Any further hints you could pass along? I had a similar issue with
adding multiple tables until I realized that I if I inserted a
paragraph between each table, it prevented the new table from
overwriting the previous one.

Thank you again for your help so far

Lorraine
 

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