Cyberdude
08-06-2006, 03:43 PM
I?ve never worked with Public variables before, and I?m unable to get a macro in Personal.xls to recognize a Public variable declared in another (open) workbook. The declaration I?m using looks like this:
Public PubVar As Long
Perhaps I am misinterpreting what Help says about Public scope:
?Variables declared using the Public statement are available to all procedures in all modules in all applications unless Option Private Module is in effect; in which case, the variables are public only within the project (http://javascript%3Cb%3E%3C/b%3E:hhobj_27.Click%28%29) in which they reside.?
I understood this to mean that the scope does include multiple open workbooks. If I?m wrong, then the problem is solved. Help defines ?Project? as a set of modules. It didn?t mention whether they have to be in the same workbook or not.
Next question: If I declare the same variable name as Public in two different modules of the same workbook, what are the implications? My tests show that the procedures in each module work ONLY with the variable instance that is declared at the top of their parent module. This seems weird. I would have thought that I?d get an error message showing multiple declarations of the same variable, but I didn?t. When I removed the declaration from one of the modules, then a macro in the other module accessed the remaining Public variable with no problem.
Public PubVar As Long
Perhaps I am misinterpreting what Help says about Public scope:
?Variables declared using the Public statement are available to all procedures in all modules in all applications unless Option Private Module is in effect; in which case, the variables are public only within the project (http://javascript%3Cb%3E%3C/b%3E:hhobj_27.Click%28%29) in which they reside.?
I understood this to mean that the scope does include multiple open workbooks. If I?m wrong, then the problem is solved. Help defines ?Project? as a set of modules. It didn?t mention whether they have to be in the same workbook or not.
Next question: If I declare the same variable name as Public in two different modules of the same workbook, what are the implications? My tests show that the procedures in each module work ONLY with the variable instance that is declared at the top of their parent module. This seems weird. I would have thought that I?d get an error message showing multiple declarations of the same variable, but I didn?t. When I removed the declaration from one of the modules, then a macro in the other module accessed the remaining Public variable with no problem.