Microsoft KB Archive/275977

= UserForm activates the first document it was loaded from =

Article ID: 275977

Article Last Modified on 1/29/2007

-

APPLIES TO


 * Microsoft Office Word 2003
 * Microsoft Word 2002 Standard Edition

-



This article was previously published under Q275977



SYMPTOMS
You create a Microsoft Word template that contains a UserForm. You then open two or more documents that use the same template. When you do this, you may unexpectedly switch to the wrong document when you show the UserForm.



CAUSE
This problem can occur if all the following conditions are true:  You create a global template that contains a macro.  The macro shows a UserForm that you can hide with a click event; for example, a command button with code similar to the following: Private Sub CommandButton1_Click

UserForm1.hide

End Sub  You create more than one document using the global template. You use the macro with one document, hide the UserForm, and then attempt to use the macro with another document created with the same template.



RESOLUTION
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers 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 requirements.

To resolve this behavior, change the code on the command button click event to unload the UserForm instead of hide the UserForm, as in the following example: Private Sub CommandButton1_Click

Unload UserForm1

End Sub

Additional query words: WD2002 prb WD2003

Keywords: kbprb KB275977

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.