Put fields into every footer

L

Legal Learning

I have a wonderful macro that I built for my client that removes the footer
they wanted as a default. It works great. However, now they want the
default to be no footer and to put one in that looks like the following in 10
pt font.

Page 1 of 3--12/2/2008--12:48:13PM--file and path

See my code below for the remove footer macho

Dim pRange As Word.Range
For Each pRange In ActiveDocument.StoryRanges
Do Until (pRange Is Nothing)
Select Case pRange.StoryType
Case wdFirstPageFooterStory, _
wdPrimaryFooterStory, wdEvenPagesFooterStory
On Error Resume Next
pRange.Tables(1).Cell(1, 1).Range.Delete
On Error GoTo 0
Case Else
'Do nothing
End Select
Set pRange = pRange.NextStoryRange
Loop
Next

Any help is GREATLY appreciated!
 
D

Doug Robbins - Word MVP

Why aren't they using a template that has the appropriate fields for that
information already set up in the footer.



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

Legal Learning

They want nothing in by default. For the folks that want one, they want a
macro to put it in. Sorry for my confusing post. Does this make sense?
 
G

Graham Mayor

A simple method would be to create the formatted footer

Page { PAGE} of { NUMPAGES } - - { CREATEDATE \@ "dd/MM/yyyy' -- 'hh:mm:ss
am/pm" } -- { FILENAME \p }

and save it as an autotext entry here called 'tFooter' then use the
following macro to insert an autotext field in the footers of the document
eg

Dim oSection As Section
Dim oFooter As HeaderFooter
Dim oRng As Range
On Error GoTo ErrorHandler
If Len(ActiveDocument.Path) = 0 Then
ActiveDocument.Save
End If
For Each oSection In ActiveDocument.Sections
For Each oFooter In oSection.Footers
If oFooter.Exists Then
Set oRng = oFooter.Range
With oRng
.Fields.Add oRng, wdFieldAutoText, "tFooter", False
.Fields.Update
End With
End If
Next oFooter
Next oSection
Exit Sub
ErrorHandler:
If Err.Number = 4198 Then
MsgBox "Document must be saved before adding footer", _
vbCritical, "Not Saved"
End If

The macro replaces any existing footer content and updates to show the
current time
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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