问题
I need a macro that places a conditional merge field with nested IF statements. Most users just copy the merge fields from one document and paste them into their final draft. However, there are numerous conditional merge fields to choose from. Using a command button that inputs the merge field instead of copying and pasting will illuminate user error and speed up this process. Any help is much appreciated.
- A macro that places a multi-nested conditional IF statement into a document.
- Below is the code I created. Where it reads, “truetext:=”True,” is where I need to insert another merge field.
Thank you for reading and for your interest!
Dim doc As Word.Document
Dim mName As String
Dim dField As Word.MailMergeDataField
Set doc = ActiveDocument
doc.MailMerge.Fields.Add Range:=Selection.Range, Name:="""Client_FirstName"""
Selection.TypeText Text:=" "
doc.MailMerge.Fields.AddIf Range:=Selection.Range, _
mergefield:="""Client_MiddleName""", Comparison:=wdMergeIfIsNotBlank, _
truetext:="True", _
falsetext:="False"
Selection.TypeText Text:=" "
doc.MailMerge.Fields.Add Range:=Selection.Range, _
Name:="""Client_LastName"""
doc.MailMerge.Fields.AddIf Range:=Selection.Range, _
mergefield:="""Client_NameSuffix""", Comparison:=wdMergeIfIsNotBlank, _
truetext:="""Client_NameSuffix""", _
falsetext:=""
Selection.TypeText Text:=" "
来源:https://stackoverflow.com/questions/65877962/vbscript-syntax-ms-word-merge-field