J'essaie de créer un mot addin qui ajoute une création d'instruction IF complexe, à partir d'une liste de champs de fusion possibles.Champ IF imbriqué dans Word VBA
Complex est
{ IF { = OR ({ COMPARE { MERGEFIELD Field_1 } <= "Value" }, { COMPARE { MERGEFIELD Field_2 } >= "Value" }) } = 1 "True Instructions" "False Instructions" }
Im essayant de faire tout cela en VBA, mais im avoir des problèmes avec mon complexe si, comme je ne peux pas obtenir le « } » pour mettre fin aux bons endroits. Si j'utilise la terminaison "Selection.EndKey Unit: = wdLine" dans tout autre endroit en dehors de la fin, cela crée un désordre et met tout le} sur cette ligne.
Voici mon code:
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
Et ce que je reçois lors de la génération du "complexe si"
{IF { = AND ({COMPARE{MERGEFIELD FHB} = "T", { COMPARE {MERGEFIELD BLAH} = "F") = 1 "If True text" "If False Text"}}}}
Mais il devrait être ceci:
{IF { = AND ({COMPARE{MERGEFIELD FHB} = "T" **}** , { COMPARE {MERGEFIELD BLAH} = "F" **}**) **}** = 1 "If True text" "If False Text"}
Si quelqu'un pouvait faire la lumière sur cette question, où vais-je me tromper? Ou S'il y a un moyen de forcer l'emplacement de la fin}, ce serait une grande Je suis très nouveau pour VBA (je suis un programmeur C++)