gpt4 book ai didi

c# - 获取 Word 中菜单项的宏命令名称

转载 作者:太空宇宙 更新时间:2023-11-03 13:46:48 25 4
gpt4 key购买 nike

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

MS Word 2010 Customize Keyboard dialog

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

最佳答案

好吧,现在是时候回答我的另一个引起过多关注的问题了。

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

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;

关于c# - 获取 Word 中菜单项的宏命令名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15084446/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com