【问题标题】:Invoke Excel macro recorder from code从代码调用 Excel 宏记录器
【发布时间】:2010-09-22 03:00:56
【问题描述】:

我需要一种在 Excel 中以编程方式启动宏记录器的方法,并为将要创建的新宏提供名称。

这可以来自 VSTO 或 VBA,或者使用 Office 互操作程序集。

有什么想法可以实现吗?

【问题讨论】:

  • 嗯,我很想得到实际工作的答案,当我弄清楚名称部分时,我试图这样做。可能是他们不允许宏记录器像其他菜单项一样运行。我会继续挖掘它。
  • 我今天没时间了,我可以访问对象但是执行命令失败。下周我会努力的。
  • @Lance Roberts:你的代码在我这边运行良好,所以 +1。

标签: excel vba vsto


【解决方案1】:

在 VBA 中:

Dim ctrlStart As CommandBarControl, ctrlStop As CommandBarControl
Set ctrlStart = Application.CommandBars.FindControl(ID:=184)
Set ctrlStop = Application.CommandBars.FindControl(ID:=2186)

ctrlStart.Execute

'name part would go here, but first you have to deal with a modal dialog

ctrlStop.Execute

RecordMacro 控件上的 Execute 方法似乎打开了一个模式对话框。无法为此提供参数,也无法执行 SendKeys 之类的操作。我看到的唯一方法是编写一个子程序,在事后重命名宏。确定新宏的名称会有点复杂,您仍然需要处理一个对话框。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-10
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    • 1970-01-01
    • 2015-07-07
    相关资源
    最近更新 更多