Bastiflew
Bastiflew

Reputation: 1166

Get the field name in VBA

I try to get field name in VBA. All I get is the result text, or the complete code. I just want the field name.

enter image description here

I try field.Code, give me : { MERGEFIELD NAME \* MERGEFORMAT } or field.Result, give me the merged result.

Sorry for french Word.

Upvotes: 3

Views: 5022

Answers (1)

Kazimierz Jawor
Kazimierz Jawor

Reputation: 19067

It seems that there isn't any property which allows to get name of MailMerge field. Therefore I could suggest the following workaround:

Sub qTest()

    Dim tmpFieldCode As String
        tmpFieldCode = ActiveDocument.MailMerge.Fields(1).Code

    Dim tmpFieldName As String
        tmpFieldName = Split(tmpFieldCode, " ")(2)

    Debug.Print tmpFieldCode   '>>  MERGEFIELD Firma
    Debug.Print tmpFieldName   '>>  Firma
End Sub

Upvotes: 3

Related Questions