MVP Cindy M.'s Attention: Add footer to word document using VBscri

S

Steve C.

Hi Cindy,
I just read your posting of 3/21 on same subject and wonder if it is
difficult to change the footer texts to adding built-in Auto Text functions
like '-PAGE' - or 'Created On'.
It is much appreciated if you are kind enough to show the VB codes for
achieving the task as you did on 3/21.
Thank you very much in advance for your attention.

Regards,

Steve C.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?U3RldmUgQy4=?=,
I just read your posting of 3/21 on same subject and wonder if it is
difficult to change the footer texts to adding built-in Auto Text functions
like '-PAGE' - or 'Created On'.
It is much appreciated if you are kind enough to show the VB codes for
achieving the task as you did on 3/21.
These are actually FIELDS; the PAGE and CREATEDATE fields, respectively. So
what you need to do are insert the field codes in the appropriate position.
Unfortunately, you haven't told me WHERE in the header/footer they should be.
For my example, I'm going to make the following assumptions:

1. Your footer has three "regions" for text: left aligned, centered,
right-aligned

2. These "regions" are defined with tab stops: a center-align tab stop in the
middle of the page; a right-align tab stop at the right margin. (This is how
Word sets up headers/footers by installation default.)

3. The page number will be centered, surrounded by dashes

4. The "Created on" will be right-aligned, with the text (as the AutoText entry
appears)

Sub CreateFooter()

Dim doc As Word.Document
Dim rngFooter As Word.Range
Dim rngTabContent As Word.Range
Dim fld As Word.Field

Set doc = ActiveDocument
Set rngFooter = _
doc.Sections(1).Footers(wdHeaderFooterPrimary).Range

Set rngTabContent = rngFooter.Duplicate
rngTabContent.Text = "left margin text" & vbTab & "- "
rngTabContent.Collapse wdCollapseEnd

Set fld = doc.Fields.Add(Range:=rngTabContent, Text:="PAGE",
PreserveFormatting:=False)

Set rngTabContent = rngFooter.Duplicate
rngTabContent.Collapse wdCollapseEnd
rngTabContent.Text = " -" & vbTab & "Created on: "
rngTabContent.Collapse wdCollapseEnd

Set fld = doc.Fields.Add(Range:=rngTabContent, Text:="CreateDate \@ " &
Chr$(34) & "MMMM d yyyy" & Chr$(34), PreserveFormatting:=False)

End Sub


Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail :)
 

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