Why must I click in document to force Word status bar to reset after running macros?



I have several toolbar macros located in a Word 2003 global template. The
macros call a COM DLL to launch specific document templates with automation.
The VB6 DLL contains all the code and userforms to launch a new document
based on the template, present the user with a dialog box, etc.

After I run the main macro and return to the document, I sometime have to
click within the document for it to regain focus. This also causes the
status bar to reset so the page number, etc. appears (status bar is blank
until I click in the document).

The code in the DLL is very careful to handle ScreenUpdating and StatusBar
as it goes along, so I don't think the problem lies in how I am setting
those. Also I have tried using Doc.Activate at the last step of the main
function in the DLL, but it doesn't seem to have any effect in this
scenario.

Another strange thing is that after I have clicked in the document, if I
then want to re-run the macro I need to click twice on the Word toolbar
button to run it (it's as though the first click is activating the window
containing the command bar). Also when I next run the userform and click on
a control, I may have to click twice because the first click is apparently
activating the form.

There seems to be a tug-of-war going on between the active document window
and my DLL app. What am I doing wrong and is there a good way to ensure the
focus is being correctly set?

Thanks
k.


.


Loading