Locking Fields in Headers and Footers

A

afswa

I need a subroutine to lock fields in the headers and footers once they have
updated. I have been trying

For Each sSection In ActiveDocument.Sections
For Each hHeader In sSection.Headers
If hHeader.Exists Then
For Each fField In hHeader.Range.Fields
fField.Unlink
Next fField
End If
Next hHeader
For Each fFooter In sSection.Footers
If fFooter.Exists Then
For Each fField In fFooter.Range.Fields
If fField.Type <> wdFieldPage Then
fField.Unlink
End If
Next fField
End If
Next fFooter
Next sSection

But it is painfully slow - there are 164 sections in the document but it is
taking around 40 minutes on a P4 with 1 Gig RAM

Is there a better way?.
 
J

Jean-Guy Marcil

afswa was telling us:
afswa nous racontait que :
I need a subroutine to lock fields in the headers and footers once
they have updated. I have been trying

For Each sSection In ActiveDocument.Sections
For Each hHeader In sSection.Headers
If hHeader.Exists Then
For Each fField In hHeader.Range.Fields
fField.Unlink
Next fField
End If
Next hHeader
For Each fFooter In sSection.Footers
If fFooter.Exists Then
For Each fField In fFooter.Range.Fields
If fField.Type <> wdFieldPage Then
fField.Unlink
End If
Next fField
End If
Next fFooter
Next sSection

But it is painfully slow - there are 164 sections in the document but
it is taking around 40 minutes on a P4 with 1 Gig RAM

Is there a better way?.

As a starter, since you want to unlink all fields, you could replace:

For Each fField In hHeader.Range.Fields
fField.Unlink
Next fField

by

hHeader.Range.Fields.Unlink

This will eliminate the need to cycle through each field.


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
A

afswa

Merci.

afswa

Jean-Guy Marcil said:
afswa was telling us:
afswa nous racontait que :


As a starter, since you want to unlink all fields, you could replace:

For Each fField In hHeader.Range.Fields
fField.Unlink
Next fField

by

hHeader.Range.Fields.Unlink

This will eliminate the need to cycle through each field.


--

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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