unique commandbar per document?

J

Jase

Hi all,
I would like to alter a custom commandbar in word depending on values stored
in the currently opened document. this bit I can do except that the
commandbar always changes for all the currently open documents. does anyone
know if its possible?
I've been trying with variations on this: (other detail omitted)

Application.CustomizationContext = ThisDocument
Set myCommandBarButton =
ActiveDocument.CommandBars.FindControl_(Type:=msoControlButton, tag:=tag)
If Not myCommandBarButton Is Nothing Then myCommandBarButton.Delete
Set myCommandBarButton = ActiveDocument.CommandBars("mycommandbar")
_.Controls.Add(Type:=msoControlButton)

this appeared to work for a while but I suspect it was just word being flakey.

I've also tried various attempts with creating/deleting commandbars instead
of buttons but to no avail.

any thoughts greatfully accepted.
thanks in advance.
 
J

Jase

clarification:
I want changes to a commandbar to be local to the document currently active.
other open documents' commandbars should not change.
 
C

Charles Kenyon

You need to set a customization context as the ActiveDocument.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
J

Jase

Thanks, I sussed that, but I found that I couldnt control the position of the
command bar well enough for my purposes. I would have preffered to be able to
control(hide/show) a single button on a global commandbar in a ice per
instance way, but the nearest I can get is to capture the documents'
windowactivate event and alter it each time i tab between open documents.

Thankyou.
 
C

Charles Kenyon

If you build the command bar in the document, it will only be available when
the document is open. If you shift to a different document it will not be
there, even if the document containing it remains open.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide


--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top