可能なマージフィールドのリストから、複雑な IF ステートメントの作成を追加する単語アドインを作成しようとしています。
コンプレックスは
{ IF { = OR ( { COMPARE { MERGEFIELD Field_1 } <= "Value" }, { COMPARE { MERGEFIELD Field_2 } >= "Value" } ) } = 1 "True Instructions" "False Instructions" }
私はこれをすべてVBAでやろうとしていますが、「}」を正しい場所で終わらせることができないため、複雑な場合に問題があります。
最後以外の場所でターミネータ「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」を生成するときに得られるものです
{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 ++プログラマーです)