Adding the Page number

P

Peter Newman

Firstly thanks to all that have helped me with my problems. Im generating a word doc ' on the fly ' from a VB6 application, inserting a combo of text and Database Fields. After loads of help i've now managed to complete that task, however there is one thing id like to add as a finishing touch, and thats 'nice' page numbering in the footer, centered aligned

so far in the footer i have our company name and a issued date, how can i put in Page - n - centeraligned in the footer

for my footer so far
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs.TabStops.ClearAl
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs.TabStops.Add Position:=InchesToPoints(1), Alignment:=wdAlignTabLef
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs.TabStops.Add Position:=InchesToPoints(9), Alignment:=wdAlignTabRigh

.Sections(1).Footers(wdHeaderFooterPrimary).Range.Font.Size =
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Font.Italic = Tru
.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertAfter vbTab & "Issued By 'Company Name' " & vbTab & "Issued - " & Dat

Is there a way to assign the page number to a variable so i can use something like this

.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertAfter vbTab & "Issued By 'Company Name' " & vbTab & "Page - " & NPage & " -" & Vbtab & "Issued - " & Dat

where Npage = Page Number
 
J

Jonathan West

Hi Peter


Try this

Dim myRange as Range
Set myRange = .Sections(1).Footers(wdHeaderFooterPrimary).Range
With myRange
.InsertAfter vbTab & "Issued By 'Company Name' " & vbTab & "Page "
.Collapse Direction:=wdCollapseEnd
NormalTemplate.AutoTextEntries("- PAGE -").Insert Where:=myRange, _
RichText:=True
.Move Unit:=wdStory, Count:=1

.InsertAfter Vbtab & "Issued - " & Date
End With


--
Regards
Jonathan West

Peter Newman said:
Firstly thanks to all that have helped me with my problems. Im generating
a word doc ' on the fly ' from a VB6 application, inserting a combo of text
and Database Fields. After loads of help i've now managed to complete that
task, however there is one thing id like to add as a finishing touch, and
thats 'nice' page numbering in the footer, centered aligned.
so far in the footer i have our company name and a issued date, how can i
put in Page - n - centeraligned in the footer ?
for my footer so far
..Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs.TabStops.ClearA
ll
..Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs.TabStops.Add
Position:=InchesToPoints(1), Alignment:=wdAlignTabLeft..Sections(1).Footers(wdHeaderFooterPrimary).Range.Paragraphs.TabStops.Add
Position:=InchesToPoints(9), Alignment:=wdAlignTabRight
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Font.Size = 7
.Sections(1).Footers(wdHeaderFooterPrimary).Range.Font.Italic = True
.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertAfter vbTab &
"Issued By 'Company Name' " & vbTab & "Issued - " & Date
Is there a way to assign the page number to a variable so i can use something like this ;

.Sections(1).Footers(wdHeaderFooterPrimary).Range.InsertAfter vbTab &
"Issued By 'Company Name' " & vbTab & "Page - " & NPage & " -" & Vbtab &
"Issued - " & Date
 
H

Helmut Weber

Hi Peter,
in most cases you'd better use a field.
I assume, that you have inserted all you need
in the footer, including the text "NPage".
---
Dim oRng As Range
Dim oSct As Section
Set oSct = ActiveDocument.Sections(1)
Set oRng = oSct.Headers(1).Range
With oRng.Find
.Text = "Npage"
If .Execute Then
oRng.Fields.Add _
Range:=oRng, _
Type:=wdFieldEmpty, _
Text:="PAGE ", _
PreserveFormatting:=True
End If
End With
End Sub
!!! Note that I have tested this on a header!!!
And there are many more ways to achieve what you want.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 

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