开发者

Invoke Excel macro recorder from code

I need a way to programatically launch the macro-recorder in Excel, and supply the name for the new macro that will get created.

This can be from VSTO or VBA, or using the Office interop assemblies.

Any ideas how this can开发者_如何转开发 be accomplished?


In 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

It looks like the Execute method on the RecordMacro control opens a modal dialog. There is no way to feed a parameter to this, or to do anything like SendKeys. The only way I see to do it is to write a sub that will rename the macro after the fact. It will be a little complicated to determine what the name of the new macro is, and you will still have a dialog box to deal with.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜