Microsoft KB Archive/289085

= Forms do not work when you start them from macro dialog box =

Article ID: 289085

Article Last Modified on 7/5/2006

-

APPLIES TO


 * Microsoft Publisher 2002 Standard Edition

-



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 &quot;loader&quot; 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:  Start Microsoft Publisher 2002, and then open the document that contains the macro that you want to run. Press ALT+F11 to open the Visual Basic Editor. In the Project window, expand the path Project/Microsoft Publisher Objects/ThisDocument, and then double-click ThisDocument. In the Object list, click Document. In the Procedure list, click Open.  Type the code that loads the user form, as in the following example: Private Sub Document_Open Load UserForm1 UserForm1.Show vbModal End Sub </li> Close the Visual Basic Editor, and then save and close the document.</li> 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.</li></ol>

Method 2: Open the user form with a loader form
To open the form with a loader form, follow these steps: <ol> Start Microsoft Publisher 2002, and then open the document that contains the macro.</li> On the Tools menu, point to Macro, and then click Visual Basic Editor.</li> On the Insert menu, click UserForm.</li> 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.</li> Double-click the Command Button.

This opens the Code window and the Command Button Click event subroutine.</li>  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. </li> In the Project window, open the module that contains the code that loads the main user form.</li>  Locate the lines of code that look like the following Load UserForm1 .     .      .   UserForm1.Show VBModal where UserForm1 is the main user form. </li>  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. </li></ol>

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

<div class="status_section">

STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.

<div class="moreinformation_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.

Additional query words: prb PUB2002

Keywords: kbbug kbpending KB289085

-

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

© Microsoft Corporation. All rights reserved.