我正在尝试从可能的合并字段列表中创建一个添加复杂 IF 语句创建的单词插件。
复杂的是
{ IF { = OR ( { COMPARE { MERGEFIELD Field_1 } <= "Value" }, { COMPARE { MERGEFIELD Field_2 } >= "Value" } ) } = 1 "True Instructions" "False Instructions" }
我试图在 VBA 中完成这一切,但如果我的 Complex 出现问题,因为我无法让“}”在正确的位置结束。
如果我在除末尾之外的任何其他位置使用终结符“Selection.EndKey Unit:=wdLine”,它会造成混乱并将所有 } 放在该行。
这是我的代码:
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="IF "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:=" = " & JointOperator1 & " ( "
'FIRST ARG
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="COMPARE "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False, Text:="MERGEFIELD " & FirstArg1
Selection.TypeText Text:=" "
Selection.TypeText Text:=ComparisonType1
Selection.TypeText Text:=" "
Selection.TypeText Text:=Chr(34) & SecondArg1 & Chr(34)
Selection.TypeText Text:=", "
'SECOND ARG
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:="COMPARE "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False, Text:="MERGEFIELD " & FirstArg2
Selection.TypeText Text:=" "
Selection.TypeText Text:=ComparisonType2
Selection.TypeText Text:=" "
Selection.TypeText Text:=Chr(34) & SecondArg2 & Chr(34)
Selection.TypeText Text:=" ) "
Selection.TypeText Text:=" = 1 "
Selection.TypeText Text:=vbCrLf & " " & Chr(34)
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:=strTempIfTrue
Selection.TypeText Text:=Chr(34) & " " & vbCrLf
Selection.TypeText Text:=" " & Chr(34)
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, _
PreserveFormatting:=False
Selection.TypeText Text:=strTempIfFalse
Selection.TypeText Text:=Chr(34)
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
这就是我在生成“复杂如果”时得到的
{IF { = AND ( {COMPARE{MERGEFIELD FHB} = "T", { COMPARE {MERGEFIELD BLAH} = "F") = 1 "If True text" "If False Text"}}}}
但应该是这样的:
{IF { = AND ( {COMPARE{MERGEFIELD FHB} = "T" **}** , { COMPARE {MERGEFIELD BLAH} = "F" **}** ) **}** = 1 "If True text" "If False Text"}
如果有人能对这件事有所了解,那我哪里错了。或者如果有一种方法可以强制结束 } 的位置,那就太好了我对 VBA 很陌生(我是 C++ 程序员)