Manipulating footer to return page number.

I

Ian B

With assistance from Graham & Gerry I now have the correct fonts in my
footers.
Next (and last) problem is to append the page number to a string being
inserted in the footer, the page number to be preferably to be formatted as
"01","02" .."99". Will never be more than 99 pages in a section.
One way which almost meets the requirement is to append a PageNum field to
the string, but as I am manipulating the footer using the code below, I do
not know how this can be done.

Again any help much appreciated. Portion of Code below.
~~~~~~~~~
sStamp = GetHex(lS)
With ActiveDocument.Sections(lS)
.Footers(wdHeaderFooterPrimary).LinkToPrevious = False
For Each oHeader In .Footers
Set oRng = oHeader.Range
With oRng
If Len(oRng) > 1 Then
.InsertAfter vbCr
End If
.Paragraphs.TabStops.ClearAll
.ParagraphFormat.TabStops.Add Position:=CentimetersToPoints(17),
Alignment:=wdAlignTabRight, Leader:=wdTabLeaderSpaces
If sCode = "B" Or sCode = "F" Then
.ParagraphFormat.TabStops.Add
Position:=CentimetersToPoints(8.5), Alignment:=wdAlignTabLeft,
Leader:=wdTabLeaderSpaces
End If
.Start = oHeader.Range.End
.Text = sStamp <<<<< PageNumber to be
added here
.End = oHeader.Range.End
.Font.Name = "Arial"
.Font.Size = 16
.Start = oHeader.Range.End
~~~~~~~~
 
D

Doug Robbins - Word MVP

To add page numbers in that format at the position of oRng, use

ActiveDocument.Fields.Add oRng, wdFieldEmpty, "Page \# 00"

Assuming that the page number is to appear after sStamp with one space
between, use

.Start = oHeader.Range.End
.Text = sStamp & " "
.End = oHeader.Range.End
.Font.Name = "Arial"
.Font.Size = 16
.Start = oHeader.Range.End
ActiveDocument.Fields.Add oRng, wdFieldEmpty, "Page \# 00"

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 
G

Graham Mayor

I suspect what you need is

For Each oHeader In .Footers
Set oRng = oHeader.Range
With oRng
If Len(oRng) > 1 Then
.InsertAfter vbCr
End If
.Paragraphs.TabStops.ClearAll
.ParagraphFormat.TabStops.Add _
Position:=CentimetersToPoints(17), _
Alignment:=wdAlignTabRight, _
Leader:=wdTabLeaderSpaces
If sCode = "B" Or sCode = "F" Then
.ParagraphFormat.TabStops.Add _
Position:=CentimetersToPoints(8.5), _
Alignment:=wdAlignTabLeft, _
Leader:=wdTabLeaderSpaces
End If
.Start = oHeader.Range.End
.Text = sStamp
.End = oHeader.Range.End
.Font.name = "Arial"
.Font.Size = 16
.InsertAfter vbTab 'I assume you want a tab before the page
number?
.Start = oHeader.Range.End
.Fields.Add oRng, wdFieldPage, "\# 00", False
End With
Next oHeader

though as this is a footer and not a header it might reduce confusion if you
rename the variable oHeader to oFooter?

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
I

Ian B

Thankyou both for your inputs.
Just some help with placement of page number.
Here is a sample of the variable sStamp:
2368-4BE18BAC-01
The page number needs to be appended thus (if page 3):
2368-4BE18BAC-01-03
All my attempts either overwrite sStamp with page number or put Page number
at the end of the footer.
I suspect my lack of knowledge of ranges is the problem. Again any pointer
much appreciated.
 

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