Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88111

Set Const Conditionally at compile time in VBA

$
0
0

I'd like to set the value of a const variable conditionally at Compile time. I thought i could achieve this using vba compiler directives #If #Else etc. as below, but have been unsuccessful so far:

#If Environ("username") = "myusername" Then
    Public Const ErrorHandling As Boolean = False
#Else
    Public Const ErrorHandling As Boolean = True
#End If

When i run this code, im getting an error that the Environ variable is undefined.
Would something like this even be possible? Or do i just have to make my 'ErrorHandling' variable Public (not Const), and set it at the initialisation of my code?

Thanks in advance,
cjk


Viewing all articles
Browse latest Browse all 88111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>