ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Set Global Variable Inside Object Module (https://www.excelbanter.com/excel-programming/398833-set-global-variable-inside-object-module.html)

Randy[_2_]

Set Global Variable Inside Object Module
 
I have a user form that I'd like to establish a global constant, but I
don't know how. I've tried:

Public Const strPW As String = "myPW"

but it errors out saying that this is "not allowed as Public members
of object modules".

Can I declare this publicly so that I don't have to do it in every
subroutine?

Thanks,
Randy


joel

Set Global Variable Inside Object Module
 
You can remove Public and it will work and still be recognized inside private
subs in your userform.

"Randy" wrote:

I have a user form that I'd like to establish a global constant, but I
don't know how. I've tried:

Public Const strPW As String = "myPW"

but it errors out saying that this is "not allowed as Public members
of object modules".

Can I declare this publicly so that I don't have to do it in every
subroutine?

Thanks,
Randy



Bob Phillips

Set Global Variable Inside Object Module
 
If you want to access it beyond the userform, you can either set it up as a
Public Const in a standard code module rather than the userform, or you
could create a public property of the userform and load it in the form
initialize event.



--
---
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Randy" wrote in message
ups.com...
I have a user form that I'd like to establish a global constant, but I
don't know how. I've tried:

Public Const strPW As String = "myPW"

but it errors out saying that this is "not allowed as Public members
of object modules".

Can I declare this publicly so that I don't have to do it in every
subroutine?

Thanks,
Randy




Randy[_2_]

Set Global Variable Inside Object Module
 
Thanks, guys. I know what to do now.

Randy



All times are GMT +1. The time now is 05:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com