S
Spiggy Topes
I have a series of macros stored in one module which I need to make as common as possible for execution in two locations. File locations will differ from one to the other, and I'd like to set it up so that all necessary changes can be made with just one line change.
Naturally, I thought of using compiler directives to bracket the constants that are used for directory names, and came up with this code:
Const LOCATION = "AWAY"
Const AT_HOME = "HOME"
Const AT_AWAY = "AWAY"
#If LOCATION = AT_HOME Then
Const GOTIT = "Home"
#Else
Const GOTIT = "Away"
#End If
Sub Run_It()
MsgBox LOCATION
MsgBox GOTIT
End Sub
....but it doesn't work, and I can't see why. Any setting of LOCATION returns "Home" in GOTTIT. "LOCATION = AT_HOME" always evaluates as True.
Same behaviour under Windows 7 and Vista, using Excel 2007 or 2010.
Any idea why this happens? I guess I can fix by replacing constants with global variables, but I'd like to know why it doesn't work this way.
Naturally, I thought of using compiler directives to bracket the constants that are used for directory names, and came up with this code:
Const LOCATION = "AWAY"
Const AT_HOME = "HOME"
Const AT_AWAY = "AWAY"
#If LOCATION = AT_HOME Then
Const GOTIT = "Home"
#Else
Const GOTIT = "Away"
#End If
Sub Run_It()
MsgBox LOCATION
MsgBox GOTIT
End Sub
....but it doesn't work, and I can't see why. Any setting of LOCATION returns "Home" in GOTTIT. "LOCATION = AT_HOME" always evaluates as True.
Same behaviour under Windows 7 and Vista, using Excel 2007 or 2010.
Any idea why this happens? I guess I can fix by replacing constants with global variables, but I'd like to know why it doesn't work this way.