Voici une macro qui met à jour tous les champs qui se trouvent en en-tête et en pied de page dans toutes les sections d'un document.

Sub maj_champ()
Dim oField As Field
Dim oSection As Section
Dim oHeader As HeaderFooter
Dim oFooter As HeaderFooter
For Each oSection In ActiveDocument.Sections
For Each oFooter In oSection.Footers
If oFooter.Exists Then
For Each oField In oFooter.Range.Fields
oField.Update
Next oField
End If
Next oFooter
For Each oHeader In oSection.Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Update
Next oField
End If
Next oHeader
Next oSection
ActiveDocument.PrintPreview
ActiveDocument.ClosePrintPreview
End Sub

 

 


Voici une macro qui met à jour les champs des en-têtes de la première section d'un document :

 

Sub maj_champ2()
Dim oField As Field
Dim oHeader As HeaderFooter

For Each oHeader In ActiveDocument.Sections(1).Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Update
Next oField
End If
Next oHeader
End Sub

 

Et pour la section en cours :

Sub maj_champ2()
Dim oField As Field
Dim oHeader As HeaderFooter

For Each oHeader In Selection.Sections(1).Headers
If oHeader.Exists Then
For Each oField In oHeader.Range.Fields
oField.Update
Next oField
End If
Next oHeader
End Sub