Question : Changing Field code of current header

Dear Experts:

With the cursor residing in some section of my document, I would like to perform the following:

Access the ODD page and EVEN page header of the section where the cursor currently resides in and change the field code {REF bookmark_DE \h} to {REF bookmark_EN \h} using VBA.

I hope this is feasible.

Thank you very much in advance.

Regards, Andreas

Answer : Changing Field code of current header

Hi Andreas, see if this works in all cases.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
Sub ModifyHeaderFields()
    Dim sec As Word.Section
    Dim rng As Word.Range
    Dim fld As Word.Field
    Dim h As Word.WdHeaderFooterIndex
    
    Set rng = Selection.Range
    Set sec = rng.Sections(1)
    For h = wdHeaderFooterPrimary To wdHeaderFooterEvenPages Step 2 'omit first page header
        For Each fld In sec.Headers(h).Range.Fields
            fld.Code.Text = Replace(fld.Code.Text, "REF bookmark_DE \h", "REF bookmark_EN \h")
        Next fld
    Next h
End Sub
Random Solutions  
 
programming4us programming4us