Microsoft KB Archive/169621

= OFF97: Displaying UserForm Designer Resets Global Variables =

Article ID: 169621

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Office 97 Standard Edition
 * Microsoft Excel 97 Standard Edition
 * Microsoft Word 97 Standard Edition
 * Microsoft PowerPoint 97 Standard Edition

-



This article was previously published under Q169621





SYMPTOMS
When you run a macro in a Visual Basic for Applications project, the value for a global variable is reset to nothing (zero).



CAUSE
This problem occurs when the following conditions are true:
 * The project includes a UserForm. -and-


 * The UserForm designer is open (the UserForm is in a window).



RESOLUTION
To resolve this problem and ensure that all global variables retain their scope, close all UserForm windows before running a macro in a Visual Basic project.



STATUS
Microsoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article.



MORE INFORMATION
The scope of a variable is determined by the way you declare the variable. In Visual Basic for Applications, you can use three kinds of variables: procedure, module, and public. To declare a global variable, use the Public, Dim, or Private keyword in the Declaration section of the module or procedure.

For additional information about the scope and lifetime of variables in Visual Basic for Applications, please see the following article in the Microsoft Knowledge Base:

141693 XL: Scope of Variables in Visual Basic for Applications

161536 How to Temporarily Hide a UserForm

