[英]How to change the formatting of a command button through a macro in VBA Excel
[英]Programmatically click a button in Excel through Macro (VBA)
我有一个自定义按钮,链接到一个做一些事情的宏。 完成后,我希望代码以编程方式单击下面突出显示的按钮(更清楚的是,打开导入 XML 对话框),因此我的用户可以看到文件选择 window 并且它将继续执行它的进一步任务。
代表形象
这是我当前的宏代码:
Option Explicit
Sub Button1_Click()
' ... All my existing macro code
' ---------- programmatically click the Import button (from Developer) here ------------
End Sub
我应该在宏中添加什么来实现这一点?
我找到了我的问题的解决方案-
% - Alt
l - Developer
t - Import
是将 XML 导入工作表的快捷键,此命令以编程方式运行快捷键,打开我想要的文件选择框。 -
Application.SendKeys ("%lt")
CommandBars.ExecuteMso 方法:
https://docs.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
“执行由idMso参数标识的控制。”
Hover 在您将其添加到功能区的按钮上,您将看到文本包括“XmlImport”
“这种方法在没有 object model 用于特定命令的情况下很有用。适用于内置按钮、切换按钮和拆分按钮的控件。”
Private Sub ExecuteMso_MoveToFolder()
' https://docs.microsoft.com/en-us/office/vba/api/Office.CommandBars.ExecuteMso
' Hover over the button where you would add it to the ribbon,
' you will see the text includes "XmlImport"
CommandBars.ExecuteMso ("XmlImport")
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.