user626528
user626528

Reputation: 14417

Invoke a ribbon action programmatically

Is it possible to invoke an action associated with a button on a ribbon tab? (That ribbon tab belongs to another Excel addin, i.e. it's not Excel's builtin)

Upvotes: 3

Views: 608

Answers (1)

anakic
anakic

Reputation: 2978

I'm confused, can't you just call the method that handles the event? E.g.

someRibbonButton_Clicked(null, null);

EDIT: Ah, it's for another plugin. You can send the shortcut key to Excel.

For example, if you send Alt,N,T to excel it will run the "Insert Table" command. You can do it from code like so:

_excelApplication.SendKeys("%", true);
_excelApplication.SendKeys("n", true);
_excelApplication.SendKeys("t", true);

SendKeys docs here.

The "%" sign means "Alt".

You can see which letters you need if you press Alt in Excel. It will show tooltips for each button showing you the correct shortcut key you need to send.

It works for built-in buttons as well as for plugin buttons.

Upvotes: 1

Related Questions