Combine Text and Page Number in Footer and Center

B

Brian

Hello All,

Long and short of it, I'm making an excel spreadsheet that creates a word
document. The part of the code that I'm having problems with is having in
the footer "Exhibit - PAGE 1" where 1 is the field Page Number and then
center the footer. I've tried many different things and came very close, but
to no avail. Can someone please help me.
 
D

Doug Robbins - Word MVP

Easier to tell you what to do if you show us the code that you have that
nearly works.

Alternatively, create a template with the Text and Page Number field in the
footer where you want it and then have your Excel code create the document
from that template.

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

Brian

Doug,

Thanks for the response. In my haste to try to get this to work I deleted
code that almost worked, replaced it with code that has an error and can't
remember the code that I had previously. I'm trying to do something akin to

With wrdDoc
With Sections(1).Footers(wdHeaderFooterFirstPage).Range
.ParagraphFormat.Alignment = wdAlignParagraphCenter
.InsertAfter "Exhibit - PAGE "
.Fields.Add Range:=Selection.Range, Type:=wdFieldPage
End With
..
..
End With

When I run it like this, I get Error Code 450 on the Fields line (which I
got by recording a macro in word and then pasting it into VBA). When I
De-activate that line (by typing ' in front of it), no error but nothing
shows up in the footer.

Brian
 
D

Doug Robbins - Word MVP

Use:

Dim wrdDoc As Document
Set wrdDoc = ActiveDocument
Dim prange As Range
With wrdDoc
Set prange = .Sections(1).Footers(wdHeaderFooterFirstPage).Range
With prange
.Text = "Exhibit - PAGE "
.ParagraphFormat.Alignment = wdAlignParagraphCenter
End With
Set prange = .Sections(1).Footers(wdHeaderFooterFirstPage).Range
prange.Collapse wdCollapseEnd
.Fields.Add Range:=prange, Type:=wdFieldPage
End With

Note that if you do not have the Different First Page option set on the
Layout tab of the Page Setup dialog, you will not see anything.

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

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