Na gut, selbst ist der Mann. Ich habe mir die Eigenschaften von Field per MsgBox anzeigen lassen und bin dann auf die Lösung gekommen. Hier der Code für Interessierte:
Code
Function FindField(ByVal fieldName As String) As Integer
'This function searches for a DOCVARIABLE field with a particular name and returns its index
Dim oField As Field
For Each oField In ActiveDocument.Fields
If oField.Code = " DOCVARIABLE " + fieldName + " \* MERGEFORMAT " Then
FindField = oField.Index
Exit Function
End If
Next
'If not found, return 0 (this is okay because the first field in the document always has index 1)
End Function
Alles anzeigen