Conditional compilation

J

Jeff Hall

Is this the right way to conditionally compile coed for Word XP?
Note that this code will appear in a function that is called repeatedly.

If Application.Version > 9 Then WordXP = True Else WordXP = False
#Const isXP = WordXP
#If isXP Then
MsgBox "Word XP +"
#Else
MsgBox "Less than XP"
#End If
 
M

martinique

I don't actually know about VBA in XP, but what you have certainly won't
work in full VB and it makes no sense as a compiler directive. The first
line: If Application.Version .... is a runtime instruction, so the value of
'WordXP' isn't known until the code is executed. But compiler instructions
are acted on at compile time, before *any* code is executed.

This is wrong in principle anyway. The idea of compiler directives is to
create different versions of the compiled code according to parameters set
by the programmer. What you're looking at is dynamic variation according to
the context in which the program is run. Just use:

If Application.Version > 9 Then
MsgBox "Word XP +"
Else
MsgBox "Less than XP"
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top