Search notes:

VBA: The #const compiler directive

The #const directive allows to declare values which can be queried as compile time with the preprocessor directives #if …. then#end if.
Unfortunately, it's not possible to access the value of a such a const value at run time (at least I would not be aware of it).
option explicit

#const txt = "bar"
#const num =  42
#const bol =  true

sub testDirectives()


   #if     txt = "foo" then
           debug.print "txt was defined to foo"
   #elseif txt = "bar" then
           debug.print "txt was defined to bar"
   #elseif txt = "baz" then
           debug.print "txt was defined to baz"
   #else
           debug.print "txt is either undefined or not defined to either foo, bar or baz"
   #end if


   #if     num         then
           debug.print "num was defined"

          #if num = 99 then
              debug.print "The value of num = 99"
          #else
              debug.print "The value of num <> 99"
          #end if
   #else
           debug.print "num was not defined"
   #end if


   #if     bol         then
           debug.print "bol is true"
   #else
           debug.print "bol is false"
   #end if


   #if     hello       then
           debug.print "hello was defined"
   #else
           debug.print "hello was not defined"
   #end if

end sub
Output:
txt was defined to bar
num was defined
The value of num <> 99
bol is true
hello was not defined

Predefined constants

Possibly predefined constants seem to be:
The win16, win32 and win64 constants identify the bitness of Office, not of the Windows installation on which Office is run.

See also

VBA compiler directives
Visual Basic for Application

Index