Microsoft KB Archive/182601

From BetaArchive Wiki

Article ID: 182601

Article Last Modified on 6/23/2005



APPLIES TO

  • Microsoft Excel 98 for Macintosh
  • Microsoft Word 98 for Macintosh



This article was previously published under Q182601


SYMPTOMS

If you assign a Microsoft Visual Basic for Applications macro to the Activate event of a UserForm, the macro may not run when you activate the UserForm.

CAUSE

The Activate event for a UserForm may not occur if all of the following conditions are true:

  • You create a macro and assign it to the Deactivate event for one UserForm. -and-


  • You create a macro and assign it to the Activate event for another UserForm. -and-


  • The UserForm with the Deactivate event macro is the active UserForm, and you run a macro that activates the second UserForm with the Activate event macro.


WORKAROUND

To work around this problem, add the Visual Basic for Applications macro code for the Deactivate event for the first UserForm to the macro that activates the second UserForm. When you do this, add the code for the Deactivate event above the code that activates the second UserForm.

STATUS

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

MORE INFORMATION

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.

Example

The following steps demonstrate the behavior described in this article:

  1. Close and save any open workbooks, and then create a new workbook.
  2. Start the Visual Basic Editor (press OPTION+F11).
  3. On the Insert menu, click UserForm.

    This step inserts UserForm1 into the project.
  4. Double-click the UserForm to display the Code module behind UserForm1.
  5. Enter the following code for the Deactivate event for the UserForm:

               Private Sub UserForm_Deactivate()
    
                 MsgBox "deactivating UserForm1"
    
              End Sub
                            
  6. Add a CommandButton to UserForm1.
  7. Enter the following code for the Click event for the CommandButton:

              Private Sub CommandButton1_Click()
    
                 UserForm2.Show
    
              End Sub
                            
  8. On the Insert menu, click UserForm.

    This step inserts UserForm2 into the project.
  9. Double-click UserForm2 to display the Code module behind the UserForm.
  10. Enter the following code for the Activate event for the UserForm:

              Private Sub UserForm_Activate()
    
                 MsgBox "activating UserForm2"
    
              End Sub
                            
  11. Switch to UserForm1, and then press F5 to run UserForm1.
  12. Click the CommandButton on UserForm1.

    A message box appears with the message "deactivating UserForm1." This confirms that the Deactivate event for UserForm1 occurred.
  13. Click OK in the message box. UserForm2 is the active UserForm, and the message box for the Activate event for UserForm2 does not appear.

Correcting the Example

To correct the example, follow these steps:

  1. Comment the code for the Deactivate event of UserForm1 by typing an apostrophe (') at the beginning of each line of code in the macro.
  2. Change the code for the CommandButton Click event to the following:

             Private Sub CommandButton1_Click()
    
                 MsgBox "deactivating UserForm1"
                 UserForm2.Show
    
              End Sub
                            
  3. Switch to UserForm1 and press F5 to run the UserForm.

    A message box displays the message "deactivating UserForm1."
  4. Click OK.

    Another message box displays the message "activating UserForm2."
  5. Click OK.

    UserForm2 is the active UserForm.
  6. Close UserForm2, and then close UserForm1.


REFERENCES

For more information about using the Activate and Deactivate events, click the Office Assistant while in the Visual Basic Editor, type activate, deactivate, click Search, and then click to view "Activate, Deactivate Events."

NOTE: If the Assistant is hidden, click the Office Assistant button on the Standard toolbar. If the Assistant is not able to answer your query, please see the following article in the Microsoft Knowledge Base:

176476 OFF: Office Assistant Not Answering Visual Basic Questions



Additional query words: XL98

Keywords: kbprogramming kbprb kbdtacode KB182601