Forms do not work when you start them from macro dialog box (289085)



The information in this article applies to:

  • Microsoft Publisher 2002

This article was previously published under Q289085

SYMPTOMS

Command buttons on user forms may not produce their expected actions. This behavior occurs when the following conditions are true:
  • The user form is modal.
  • The user form is displayed as part of the execution of a macro that is run from the Macros shortcut menu.

CAUSE

When you start a Microsoft Visual Basic for Applications UserForm from the Macros dialog box, Microsoft Publisher is in what is called a modal state. When this happens, all Visual Basic Editor events are frozen. Forms do not work because Visual Basic Editor does not respond to events when Publisher is in a modal state.

When Publisher is in the modal state, the macros that you have attached to the form do not function.

WORKAROUND

To work around this issue, use one of the following methods. The methods are the following:
  • Attach the macro that opens the user form to an event that is associated with your publication, such as the Document Open event.
  • Open a "loader" form in the modeless state, and then load the main form in the fully modal state from the loader form.
  • Open the form in the modeless state.

Method 1: Attach the macro to an event

To attach the macro to the document's Open event, follow these steps:
  1. Start Microsoft Publisher 2002, and then open the document that contains the macro that you want to run.
  2. Press ALT+F11 to open the Visual Basic Editor.
  3. In the Project window, expand the path Project/Microsoft Publisher Objects/ThisDocument, and then double-click ThisDocument.
  4. In the Object list, click Document.
  5. In the Procedure list, click Open.
  6. Type the code that loads the user form, as in the following example:
    Private Sub Document_Open()
       Load UserForm1
       UserForm1.Show vbModal
    End Sub
    					
  7. Close the Visual Basic Editor, and then save and close the document.
  8. Reopen the publication.

    Depending on your Macro Security settings, you may be prompted with the macro virus warning. Click Enable.

    The user form is displayed.

Method 2: Open the user form with a loader form

To open the form with a loader form, follow these steps:
  1. Start Microsoft Publisher 2002, and then open the document that contains the macro.
  2. On the Tools menu, point to Macro, and then click Visual Basic Editor.
  3. On the Insert menu, click UserForm.
  4. Click the Command Button control on the Toolbox palette, and then add it to the new form. Make any modifications that you want to the form and the button.
  5. Double-click the Command Button.

    This opens the Code window and the Command Button Click event subroutine.
  6. Edit the subroutine to look like the following
    Private Sub CommandButton1_Click()
       Unload UserForm2
       Load UserForm1
       UserForm1.Show vbModal
    End Sub
    						
    where CommandButton1 is the button on the loader form, UserForm1 is the main user form, and UserForm2 is the loader form.
  7. In the Project window, open the module that contains the code that loads the main user form.
  8. Locate the lines of code that look like the following
       Load UserForm1
          .
          .
          .
       UserForm1.Show VBModal
    						
    where UserForm1 is the main user form.
  9. Edit the lines of code so that they look like the following
       Load UserForm2
          .
          .
          .
       UserForm2.Show VBModeless   
    						
    where UserForm2 is the loader form that you just created.

Method 3: Open the user form with the modeless option

To open the form with the modeless option, follow these steps:
  1. Start Microsoft Publisher 2002, and then open the document containing the macro.
  2. On the Tools menu, point to Macro, and then click Macros.
  3. In the Macro Name list, select the macro that opens the user form, and then click Edit.
  4. Find the line of code that opens the user form, which typically looks like
    <formname>.Show
    						
    where <formname> is the name of the user form being displayed.
  5. Edit the line by replacing vbModal with vbModeless.

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

If you run the module from the Visual Basic Editor, it is executed without a problem. This also works from the Macro dialog box if the form is modeless (which many times is not a viable option).

User forms and other windows can be opened so that they are either modal or modeless. When a window is modal, no other window can become the active window while the modal window remains open; alert messages and other high-priority displays are usually modal. Most other windows are modeless, which means that they can become inactive and have other windows appear in front of them as circumstances require.

When a user form is being opened by a macro, the instruction that opens the form may use the options vbModal or vbModeless to determine which way the form is to be displayed. If neither is specified, the form will be modal. When a macro is run from the Tools menu and the macro opens a user form in the modal state, the actions of the macro host are suspended while the form is open. The result is that command button actions may not take place as intended. This behavior does not occur when the macro that opens the form is initiated by an event such as the document's Open event.

Modification Type:MinorLast Reviewed:7/5/2006
Keywords:kbbug kbpending KB289085