Word 2007 +通过宏使用命令?
我想知道是否可以通过 vba 宏触发 Word 命令?我本质上想做的是让用户更容易打开新文档或模板窗口,您可以通过“新建 -->”找到该窗口。文档-->我的模板
显示我可以添加自定义选项卡(在 Word 2010 中至少如此)。但我已经使用 Microsoft Office 的自定义 UI 编辑器添加了自定义选项卡。但在尝试自定义功能区时它不会显示。我还尝试录制一个宏,然后打开一个窗口,您可以在其中选择要打开的模板。但它没有记录使窗口实际出现的动作。
有什么想法吗?
I was wondering if it's possible to fire Word commands via vba macros? What I'm essentually trying to do is to make it easier for users to open the New document or template window that you can find via New --> Document --> My templates
I see that I can add a custom tab, alteast in Word 2010. But I've already got a custom tab I've added using Custom UI Editor for Microsoft Office. But it doesn't show up when trying to customize the Ribbon. I also tried to record a macro and just open the window where you choose which template you want to open. But it didn't record the action that makes the window actually appear.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的,尽管 Word 2010 中的 Backstage 视图使这有点棘手。基本上,Word 附带了许多控制其命令的内置宏,并且可以通过 VBA 访问这些宏。通过显示开发人员选项卡,单击宏按钮,然后将“宏”对话框的宏位于:菜单更改为显示 Word 命令:
要通过 VBA 访问“我的模板”对话框,请使用以下代码:
FileNewDialog 访问现有模板用于显示后台视图的 Word 宏Sendkeys 使用 Alt 键击键来操作和打开“我的模板”对话框(有关 SendKeys 的更多信息,请参阅 Word 2010 VBA 帮助条目)。将代码放入 Sub 中并创建要执行的 QAT 或功能区按钮,您应该可以开始了。
关于测试 SendKeys 的重要说明:无法通过在 VBA IDE 中单步执行代码来测试 SendKeys,因为它在运行时发出的击键会在执行时发送到活动窗口(这将是VBA 开发窗口)。要测试 SendKeys,请保存宏并将其附加到 QAT 按钮,可以根据需要按下该按钮进行测试。
Yes this is possible, although the Backstage view in Word 2010 makes this a little tricky. Basically, Word comes with many built-in macros that control its commands and that are accessible via VBA. These commands can be found by displaying the Developer Tab, clicking the Macros button, and changing the Macros in: menu of the Macros dialog box to display Word commands:
To access the My templates dialog box via VBA, use this code:
FileNewDialog accesses the existing Word macro for displaying Backstage view and Sendkeys uses the Alt-key keystrokes to maneuver and open the My templates dialog box (see the Word 2010 VBA help entry for more on SendKeys). Place the code into a Sub and create a QAT or Ribbon button to execute and you should be good to go.
Important note about testing SendKeys: SendKeys cannot be tested by stepping through the code in the VBA IDE as the keystrokes it sends out when running are sent to the active window at the time of execution (which would be the VBA development window). To test SendKeys, save the macro and attach it to a QAT button, which can be depressed, as needed, for testing.