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. MORE INFORMATIONMicrosoft provides programming examples 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. This article assumes that you
are familiar with the programming language being demonstrated and the tools used to
create and debug procedures. Microsoft support professionals can help explain the functionality
of a particular procedure, but they will not modify these examples to provide added
functionality or construct procedures to meet your specific needs. If you have limited
programming experience, you may want to contact a Microsoft Certified Solution Provider
or the Microsoft fee-based consulting line at (800) 936-5200. For more information about
Microsoft Certified Solution Providers, please see the following page on the World Wide Web:
http://www.microsoft.com/mcsp/For more information about the support options available from Microsoft, please see the following page on the World Wide Web: http://www.microsoft.com/support/supportnet/overview/overview.aspThe 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:
REFERENCES
For 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."
Additional query words: 97 XL97
Keywords : kbprg kbdta |
Last Reviewed: July 12, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |