Public Variables Are Not Seen on Modules for Sheet or UserFormLast reviewed: March 13, 1998Article ID: Q162971 |
The information in this article applies to:
SYMPTOMSIf you declare a public variable on a Visual Basic for Applications code module that is associated with an object, such as a UserForm or a Worksheet object, only the procedures in the code module in which you declare the variable can access the value the variable stores.
CAUSEA variable that you declare with the Public statement in code modules that are associated with an object, such as a UserForm and Worksheet object, is available only to the module in which you declare it.
RESOLUTIONIf you want to access a public variable in all procedures in all modules of a project, declare the variable on a general module. To insert a general module in a project, click Module on the Insert menu.
STATUSThis behavior is by design of Microsoft Excel 97.
MORE INFORMATIONMicrosoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400. The following examples demonstrate the difference between declaring a public variable in a general module and declaring a public variable in a code module that is associated with an object.
Declaring a Public Variable in a Code Module Associated with an ObjectThe following example declares a public variable in a code module that is associated with an object:
Declaring a Public Variable in the General ModuleThe following example declares a public variable in the general module:
REFERENCESFor more information about the scope of variables, click the Office Assistant in the Visual Basic Editor, type "scope," click Search, and then click to view "Understanding Scope and Visibility." NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If Visual Basic for Applications Help is not installed on your computer, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q120802 TITLE : Office: How to Add/Remove a Single Office Program or Component |
Additional query words: 97 XL97
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |