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
[email protected]
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
[email protected]
Word MVP site: http://www.word.mvps.org
 
Top