Forcing a custom commandbar to remain with the document that creates it.

12-01-2003, 01:11 AM
I have a Word document that is used as a crude label database. I have written a VBA macro [let's call it "label_creator"] that copies a particular label to the cells of a table in a new document that it creates.

As the users of the document are not experts, I want to add a custom commandbar with popup control and button to the "database" document. This is intended to let the users click a simple menu command to create their labels. I have a second VBA macro [let's call that "cb_creator"] that creates the commandbar when the database document is opened. I want to delete this command bar when I close the database document.

The problem I have is that when I create the new document using ["label_creator"] the custom commandbar appears on the menu bar of the new document, and is no longer on the menu bar of the database document. I want to keep the commandbar with the latter and not have it appear in the new document.

Can anyone tell me a way of keeping the custom commandbar with my database document in these circumstances?


12-01-2003, 02:17 AM
CommandBars belong to the Application object, not the Document. You should use the 'WindowDeactivate' event of the Application object to detect the current Document, and remove or add the CammandBar as appropriate.

To see how to reference the Application events, check out this thread:

12-29-2003, 08:19 AM
CommandBars belong to the Application object...

I have a few hours at last to play with this. Thank you for reminding me to look at the object hierarchy.

12-30-2003, 04:05 AM
Thanks, Timbo.

I have my label database custom controls now working as I want them, though the code is working too hard and I need to work on my understanding of the object model given I have had trouble referencing my custom controls. However, without your steering I wouldn't known where to start.


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum