Discussion:
Overriding Word Commands
(too old to reply)
John
2004-12-08 22:44:13 UTC
Permalink
I am writing an addin in C# which needs to override some of the commands in
word. I can attach my event to a button's Click event but the button's
Execute method will still run. Without using VBA at all, is there a way in
my addin to bypass this?

Thanks in advance,
John
Tom Winter
2004-12-09 14:32:23 UTC
Permalink
It's been a long time, but I believe you need to create a macro (yes, a
macro!) with the same name as the Word command, for example, FileOpen. I
don't know as though you can do this type of thing with just code. I could
be wrong though; I've never done this myself. Perhaps one of the other
old-timers around might be able to give more details.
--
Tom Winter
***@NoSpam.AmosFiveSix.com
www.AmosFiveSix.com
Post by John
I am writing an addin in C# which needs to override some of the commands in
word. I can attach my event to a button's Click event but the button's
Execute method will still run. Without using VBA at all, is there a way in
my addin to bypass this?
Thanks in advance,
John
John
2004-12-09 18:35:17 UTC
Permalink
Tom,

Thank you for your input, I am aware of the macro bit (and it does work) but
they are not allowed in this project.

Thanks again,
John
Post by Tom Winter
It's been a long time, but I believe you need to create a macro (yes, a
macro!) with the same name as the Word command, for example, FileOpen. I
don't know as though you can do this type of thing with just code. I could
be wrong though; I've never done this myself. Perhaps one of the other
old-timers around might be able to give more details.
--
Tom Winter
www.AmosFiveSix.com
John
2004-12-09 18:36:38 UTC
Permalink
Possibly there is another group I should ask this question in?

Thank you,
John
Charles Kenyon
2004-12-09 21:38:05 UTC
Permalink
You are asking in the correct newsgroup and I don't think anyone knows of a
way to intercept other than through use of a macro.
--
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

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
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.
Post by John
Possibly there is another group I should ask this question in?
Thank you,
John
John
2004-12-09 22:56:24 UTC
Permalink
After a few hours of actual research turning up nothing, I disassembled the
Office interop to find the click event information regarding
CommandBarButtons. The event requires a method returning void and having
two params: CommandBarButton cmdBarbutton (the button that was just
clicked), ref bool cancel (this is an [in, out] flag allowing you to turn
off the default functionality of the button).

So, set the second referenced param to true and Word's code will not run.
Unless you are using a CommandBarPopup button which allows you to select
from a CommandBar that will popup when the arrow is clicked or by just
clicking the button itself (look at the Tables and Borders toolbar for
examples - borders, cell alignment, etc...).

And there you have it. Still have to figure out the Popup button but am on
my way.

Thanks again
John

Loading...