how to disable command buttons like word does?

J

Jase

I have noticed that if I open 2 word documents so that I can see them both at
the same time and select some text in just one of them, that the COPY
commandbutton is enabled on the document with the selection, but not on the
one without.
I want to replicate this, but when I try with a custom commandbutton, the
buttons on both documents are either enabled or disabled. how can i get the
same behaviour as words built in buttons? how can I get it to display both
states?

Thanks in advance.
Jason.
 
J

Jezebel

It's a heap of work, but you need to trap the WindowSelectionChange event,
then enable/disable your buttons according to the new context.
 
T

Tony Jollans

The Copy button is enabled when there is something selected in that window
which can be copied. If one of your documents has nothing selected then the
copy button will be disabled in that document. It doesn't matter how many
Word windows you have.

If you have a separate copy of your custom commandbar in each document
(rather than a single one in the template, or normal template) you can
replicate this behaviour.
 
J

Jase

ok I know I can change a button globally by hooking the WindowActivate event
I tried that and its ok but not perfect.
I also know that I can create individual commandbars in each document
context instead of globally and control the buttons that way too.
what I'm figuring though is that word has its built in commandbars and they
are not separate copies for each doc (I dont think), but they can display
different button states.
So I'm wondering if its possible to get the windows handle of the actual
button in question (since there can be only one handle per button) and maybe
send a windows api Function EnableMenuItem to try to enable/disable it
individually.
is this likely to work? anyone got code, or a better solution?

thanks.
 
J

Jezebel

As previously suggested, trap the WindowSelectionChange event, and configure
your buttons according to the selection context. SelectionChange includes
switching between documents.
 
J

Jase

Thankyou for your submission, but it wont solve the original problem.

The outcome I wanted was that if more than one document is visible at the
same time then each should show the command button in their respective
correct states.
Your solution will always show the button in the same state on all the
documents. I understand that it will change when each document becomes active
but its just not as nice as all the buttons being correct if you have all the
documents simultaneously visible onscreen. Using the WindowActivate event
instead of the WindowSelectionChange event acheives the same thing but with
potentially less events being fired.

thankyou for your efforts though.
Jason.
 
T

Tony Jollans

You are presuming a lot about how Word does its own stuff. What makes you
think it doesn't have separate command bars? FWIW my guess would be that
Word has one copy of the command bar for each window in the taskbar - but it
can only be a guess.

Even if you get the window handle it won't help you. If you have one icon,
it has one state. If you want to see the same icon in two (or more)
different states at the same time you will have to have two (or more) copies
of it.

Why don't you want to use a customization context? That is the most obvious,
and I think best, solution.
 
J

Jase

ok fair point. you are correct.
it does indeed look like the word standard toolbar is a unique copy for each
document. (I tried playing with application.commandbars("standard").visible)

The reason I didnt want to use multiple command bars is because I wanted to
simply store my custom commandbar in a separate template that can be easilly
customised by my clients for their own purposes, and storing
also I need the toolbar even if there is no document, so I guess I'd have to
monitor that and create one specially for that situation when it occurs? I'm
not sure.

thanks
Jason.
 

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