UserForm activates the first document it was loaded from (275977)



The information in this article applies to:

  • Microsoft Office Word 2003
  • Microsoft Word 2002

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
				

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbprb KB275977