Thread: word 2007 macro
View Single Post
  #2   Report Post  
Posted to microsoft.public.word.newusers
Doug Robbins - Word MVP on news.microsoft.com Doug Robbins - Word MVP on news.microsoft.com is offline
external usenet poster
 
Posts: 407
Default word 2007 macro

The following will add a { filename \p } field to the primary footer of the
first section of the document that is active when it is run:

With ActiveDocument
.Fields.Add .Sections(1).Footers(wdHeaderFooterPrimary).Range,
wdFieldEmpty, "filename \p"
End With

It would be better however to create a new template in which you have this
field already inserted and then use that template to create the documents
that you want to have this information in the footer. (Do not add the field
to the Normal.Dot 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

"perkin5" wrote in message
...
I am trying to record a macro to add the filepath to the page footer.
Having saved the page and recorded the macro, I get an error message:
Run-time error 5941. The requested member of the collection does not
exist.

The debugger shows the following code:

Sub Macro1()
'
' Macro1 Macro
'
'
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"FILENAME ", PreserveFormatting:=True
End Sub
Sub Macro2()
'
' Macro2 Macro
'
'
WordBasic.ViewFooterOnly
ActiveDocument.AttachedTemplate.BuildingBlockEntri es("
Blank").Insert _
Whe=Selection.Range, RichText:=True
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty,
Text:= _
"FILENAME ", PreserveFormatting:=True
End Sub

The two lines beginning 'ActiveDocument...' are highlighted.

Can anyone help me to sort this out?