VBA Word Footers with multiple fileds...

M

MikeL

Good day... The fact that I'm working at 5:00pm on a Saturday instead of
outside enjoying the Florida Sunshine should should show how either I can't
see the forest through the trees or, finally going to give in and ask for
help... Checked all the usual sorces, even ordered some books, drove 30 miles
to find a book that didn't help...

Tried to record a macro that created footers... Unfortuneatly, the macro's
wont play... (I would consider this a bug, but some would say it's a
feature...)

Also, read the help files that the MVP suggested (always try that first...)
Teach a man to fish...

We are converting our Word 2003 Macro's to Word 2007. Having difficulties
with the Footer which contains three parts... Left - has Printed: w/current
date... Center has current file name, and the right has Page: x of y...

Tried many variations... Some from books some from help... Here's 2 of the
ones...

1: (Doesn't work - get's error 5941)
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntries( _
" Blank (Three Columns)").Insert Where:=Selection.Range,
RichText:=True
Selection.TypeText Text:="Printed: "
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"DATE \@ ""M/d/yyyy h:mm am/pm"" ", PreserveFormatting:=True
Selection.MoveRight Unit:=wdCharacter, Count:=2
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
"FILENAME ", PreserveFormatting:=True
Selection.MoveRight Unit:=wdCharacter, Count:=2
ActiveDocument.AttachedTemplate.BuildingBlockEntries("Bold Numbers"). _
Insert Where:=Selection.Range, RichText:=True
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument

2. (Works but only one field... Need Building block entries???)

Private Sub test()


WordBasic.ViewFooterOnly

ActiveDocument.Sections(ActiveDocument.Sections.Count).Footers(wdHeaderFooterPrimary).Range.Select

With Selection
.Paragraphs(1).Alignment = wdAlignParagraphRight
.TypeText Text:="Page "
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="PAGE ",
PreserveFormatting:=True
.TypeText Text:=" of "
.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:="NUMPAGES
", PreserveFormatting:=True
End With


Many thanks... Hope you can help....
 

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