Reputation: 3328
I'm developing an addon for MS Word 2010 using VSTO. The Word has a "Customize keyboard" dialog:
"Commands" list contains built-in macro commands each assigned to some menu or action. They can be executed from VSTO with Application.Run()
method.
I need to obtain records in form "Menu item name" - "Macro command name" - "Keyboard Shortcut" for the currently installed instance of Word.
What I tried so far:
Application.CustomizationContext = Application.NormalTemplate;
foreach (CommandBar bar in Application.CommandBars)
{
// Name of menu group
Application.Selection.InsertAfter(bar.NameLocal + "\n");
foreach (CommandBarControl control in bar.Controls)
{
// Human-readable name
Application.Selection.InsertAfter("\nName:" + control.accName
// Broad description
+ "\nDescription:" + control.DescriptionText
// Keyboard shortcut
+ "\nShortcut:" + control.accKeyboardShortcut);
}
}
Unfortunately CommandBarControl
doesn't contain macro command name field. I'm wondering how to gather this and glue all together?
Upvotes: 2
Views: 1219
Reputation: 3328
OK, it's time now to answer another my question which has got too much attention.
There's a bunch of Excel tables for each version of Microsoft Office which contain ID, command name, default shortcuts and some other information. Here's for 2010 version. Using the provided tables it's now easy to obtain all we need:
var id = // Obtain from downloaded bundle
var name = // Obtain from downloaded bundle
var control = Application.CommandBars.FindControl(Id:id);
var description = control.DescriptionText;
var caption = control.Caption;
var shortcut = control.accKeyboardShortcut;
var parentControl = control.Parent;
Upvotes: 1