tags:

views:

67

answers:

1

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?

+2  A: 

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.

Lance Roberts