Remove an autotext field in all footers

L

Legal Learning

I have the following code that puts in an AutoText entry for a path name in
footers. All footers regardless of how many sections, pages, etc. How do I
delete them?


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, "rlrfooter", 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

Thanks in advance for any help.
 
G

Graham Mayor

Dim OSection As Section
Dim oFooter As HeaderFooter
Dim oField As Field
Dim oRng As Range

For Each OSection In ActiveDocument.Sections
For Each oFooter In OSection.Footers
If oFooter.Exists Then
Set oRng = oFooter.Range
For Each oField In oRng.Fields
If oField.Type = wdFieldAutoText Then
oField.Delete
End If
Next oField
End If
Next oFooter
Next OSection


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
L

Legal Learning

You know -- I think it has finally sunk into this old brain, Graham. How
simple you have made it. I admire your skill and abilities. Amazing to me.
You rock!

I do have one more question and it's just a user interface issue. When
adding a macro to the toolbar, it is quite annoying when I can't see the
entire name of the macro in the customize dialog. Is there a way of making
the names visible? They don't show when selecting them. Can't see a way of
making that window bigger either. Just aggraving as I have a lot of macros
in this addin. Most don't go into the toolbar but when they do....
 
L

Legal Learning

Actually, I do that already. I create the module, name the module and then
the macro. This particular addin is a tool for law firms and one of their
modules called Firm toolbar. I would like to keep all macros that go on the
Firm toolbar there.

Graham, Thanks again for all of your wonderful 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