![]() |
|
|
|
#1
|
||||
|
||||
|
If you declare a Public variable in a class module (for example a worksheet or ThisWorkbook module) then the variable may only be accessed as a member of that class. Therefore you must refer to it using syntax such as Sheet1.Variablename or ThisWorkbook.Variablename. If the variable is declared in a normal module, you may simply refer to it using its name from any other module in the workbook.
|
|
#2
|
|||
|
|||
|
Quote:
I have already tried that. It seems to work. Let's see. Best regards, Officer_Bierschnitt |
|
#3
|
|||
|
|||
|
The reason for declaring them is a separate module is just hygiene. They are not specific to any other module (that's why they're public), and keeping them together lets you find them all at a glance. For someone trying to understand your code, it's a good place to start reading.
Public variables have their place, but should be used only after careful consideration of the alternatives. In general, they can make code harder to debug and maintain. The only code I might include in that module is a routine that initializes those variables. |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Run Time Error '91': Object variable or With block variable not set using Catalogue Mailmerge | Berryblue | Mail Merge | 1 | 11-13-2014 05:36 PM |
Modelling training modules
|
Vincent | Project | 3 | 09-03-2014 05:37 PM |
Run-time error 91 object variable or with block variable not set
|
JUST ME | Word VBA | 4 | 03-25-2014 06:56 AM |
Empty Modules
|
Greg S. | Excel Programming | 2 | 07-30-2013 01:38 PM |
Run-time error '91': Object variable or With block variable not set
|
tinfanide | Excel Programming | 2 | 06-10-2012 10:17 AM |