Pages....

H

howard

My goal is to add a 'Page x of y' string in my footer. Stickler is I am
creating the whole doc in code. I have not seen a way to insert a fieldcode
programmatically. Can this be done? or is there a better way?
 
H

Helmut Weber

Hi,

simple example for header consisting of
1 paragraph only.
Inserts at the end of the paragraph.

' wdHeaderFooterPrimary = 1
Dim rTmp As Range
Set rTmp = ActiveDocument.Sections(1).Headers(1).Range
With rTmp
.InsertAfter "Page "
.Collapse direction:=wdCollapseEnd
.Fields.Add Range:=rTmp, Text:="PAGE"
.End = .Paragraphs(1).Range.End
.InsertAfter " of "
.Collapse direction:=wdCollapseEnd
.Fields.Add Range:=rTmp, Text:="NUMPAGES"
End With

I left some options out for brevity.
There might be still simpler solutions.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
H

howard

Helmut, Danke - works like a charm, just a few minor changes to run from VFP
and it works great.

Howard
 

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