Macro to remove date field, page number field

L

Legal Learning

as well as file and path name field. These fields are located in the first
cell of a one row table located in every footer in every section (also first
page footer exists). How can I delete all of these fields in a macro?

I appreciate any help regarding this.

Using Word 2003
 
G

Greg Maxey

The first macro will delete all fields in a document. The second should do
what you have specifically asked for.

Sub DeleteAllFields()
Dim pRange As Word.Range
For Each pRange In ActiveDocument.StoryRanges
Do
With pRange.Fields
While .Count > 0
.Item(1).Delete
Wend
End With
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
End Sub
Sub DeleteSelectedFields()
Dim pRange As Word.Range
Dim oFld As Field
For Each pRange In ActiveDocument.StoryRanges
Select Case pRange.StoryType
Case wdFirstPageFooterStory, _
wdPrimaryFooterStory, wdEvenPagesFooterStory
For Each oFld In pRange.Fields
Select Case oFld.Type
Case wdFieldPage, wdFieldDate, _
wdFieldFileName
oFld.Delete
Case Else
'Do Nothing
End Select
Next
Case Else
'Do nothing
End Select
Next
End Sub
 
H

Helmut Weber

Hi,

just to get you going:

http://word.mvps.org/faqs/customization/ReplaceAnywhere.htm

Then, you may have to loop through all the fields
in the storyrange and check their type.

See help for:
type property as it applies to the field, formfield [...] objects.

IMHO, there is no
"file and path name" field.

Only a field "filename" with an additional switch.

FILENAME \p \* MERGEFORMAT

as opposed to

FILENAME \* MERGEFORMAT

So you would have to check the field code.

You may try to use goto as well,
but I wouldn't recommend it,
as it seems to need the selection
for finding out, whether the execution was successfull.


HTH

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
L

Legal Learning

Thanks very much. This was very helpful. I will tweak it to delete the time
field and figure out how to not delete the second page number field (which
they want to keep). You are very good!
 
L

Legal Learning

Thank you very much Helmut! Hope you are getting as much snow as we are in
Vail Colorado! Take care
 
L

Legal Learning

I am now having trouble getting the page number back into the second cell of
a one row table in the footer. This is with as many sections as there might
be in the document but only on wdPrimaryFooterStory. Can you help me with
that?
 

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