我正在使用 VSTO 为 MS Word 2010 开发一个插件。Word 有一个“自定义键盘”对话框:
“命令”列表包含内置宏命令,每个命令都分配给某个菜单或操作。它们可以通过Application.Run()
方法从 VSTO 执行。
我需要以“菜单项名称”-“宏命令名称”-“键盘快捷键”的形式获取当前安装的 Word 实例的记录。
到目前为止我尝试了什么:
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);
}
}
不幸CommandBarControl
的是不包含宏命令名称字段。我想知道如何收集这些并将它们粘合在一起?