简体   繁体   中英

VBA MS Word conditional formatting

I have a VBA code that gives a value in a variable and then adds the variable in a document

Dim NoGFIs As Integer
NoGFIs = 1
ActiveDocument.Variables.Add Name:="GFIs ", Value:=NoGFIs 

and I used a conditional statement in the word document

No of GFIs: {DOCVARIABLE GFIs}
Check IF: {IF <<GFIs>> = 1 "ONE" "NOT ONE"

But the outcome shows that something is wrong:

No of GFIs: 1
Check IF: NOT ONE

It shows that the GFIs value gets out from the VBA to the document, but IF fails to evaluate it?? Has anyone seen anything like that before?

Your if condition seems to be wrong. Please try the below:

{ IF { DOCVARIABLE GFIs \\* MERGEFORMAT } = 1 "ONE" "NOT ONE"\\* MERGEFORMAT }

Also, did you notice the trailing space in your variable name "GFIs " in ActiveDocument.Variables.Add Name:="GFIs ", Value:=NoGFIs ?

Results:

没有一个 一

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM