View Single Post
 
Old 07-04-2022, 11:16 PM
avogt avogt is offline Windows 7 64bit Office 2016
Novice
 
Join Date: Apr 2018
Posts: 4
avogt is on a distinguished road
Default Edit Reference in Word bv VBA

Hello,
I try to insert a Reference in Word via VBA by code:
Code:
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
Selection.EndKey Unit:=wdStory
Selection.InsertCrossReference ReferenceType:="Textmarke", ReferenceKind:=wdContentText, _
ReferenceItem:="T_LIEFERANTENERGAENZUNG_BERECHNUNG", InsertAsHyperlink:=True, _
IncludePosition:=False, SeparateNumbers:=False, SeparatorString:=" "
But I need to add the "\*MERGEFORMAT" formatting to this reference.
So I tried to loop trough all fields by code:
Code:
Dim fieldLoop As Field
    Dim fieldText As String
    For Each fieldLoop In ActiveDocument.Fields
       If InStr(0, fieldLoop.Code.Text, "REF T_LIEFERANTENERGAENZUNG_BERECHNUNG", 1) Then
          fieldText = fieldLoop.Code.Text
          If InStr(1, fieldText, " \h", 1) And Not InStr(1, fieldText, " \* MERGEFORMAT", 1) Then
             fieldText = fieldText & " \* MERGEFORMAT "
             fieldLoop.Code.Text = fieldText
           End If
        End If
    Next
But the Loop does not find the Reference I added before..

Any Ideas how to add the formating to this field?
It is located in the header on page 2..

thanks
Andreas
Reply With Quote