2

我正在使用 VSTO 为 MS Word 2010 开发一个插件。Word 有一个“自定义键盘”对话框:

MS Word 2010 自定义键盘对话框

“命令”列表包含内置宏命令,每个命令都分配给某个菜单或操作。它们可以通过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的是不包含宏命令名称字段。我想知道如何收集这些并将它们粘合在一起?

4

1 回答 1

1

好的,现在是时候回答另一个我的问题了,这个问题已经引起了太多关注。

每个版本的 Microsoft Office 都有一堆 Excel 表格,其中包含 ID、命令名称、默认快捷方式和一些其他信息。这是2010 版的。使用提供的表格,现在很容易获得我们需要的一切:

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;
于 2013-03-14T09:50:14.910 回答