Generating Code in Excel / Macro Recorder Manipulation

M

mginter

First time poster, but longtime reader... Stumped with a level of
functionality that I'd like to put into a custom application. I've
built a program that allows users to setup templates for converting
existing spreadsheets (things like moving data, adding cells/formulas,
changing formatting, etc.). Each conversion step can be manually setup
through the program's UI or through forms directly inside Excel. The
one feature that I'd like to have is the ability for a user to record
their set of custom steps (as a macro) and let my program grab the code
from the created macro and store it with the template in a database.
It can then be reloaded and run when a spreadsheet is converted using
said template.

I've got the functionality to get the code through VBIDE, but stumped
on getting the process started.

So, I've hunted and hunted and there's the RecordMacro function which
is misleading since it really doesn't do anything unless the recorder
is actually running... I can't find anyway to programmatically start
the recorder... it's not an object that I can see... I don't want to
have the user start the recorder because (ideally) I'd like to be able
to default the name of the macro to what I want.

I'd like there to be a way to do what I want and maybe I'm just going
about it wrong...

Appreciate any help anyone can offer - even if it's some sort of
third-party tool.

This program was written in VB6 and this would need to apply to Excel
2000 and XP at the least with application to Excel 2003 beling a plus!
 
D

Dave Peterson

I couldn't get this to work for me--but maybe it'll work ok for you:

Option Explicit
Sub testme02()

Dim ctrl As CommandBarControl
Set ctrl = Application.CommandBars.FindControl(ID:=184)

SendKeys "qwer{Enter}"
ctrl.Execute

End Sub

qwer was the name I wanted to use for the macro.

=======
Are you sure you really want to do this? It sounds very, very dangerous to me.
Heck, when I record macros, I have lots of missteps and ranges that are specific
to the data that I was using when I recorded the macro.

And how you gonna tell them to stop recording???
 
M

Mothra75

Yep, thought about the danger, but it's a "feature" that I'd like to
include. I'm only including it for changes that a user might want to
make that I cannot accomodate through the software... the software's
really broad, but the macro recorder would be encouraged for use only
in situations where the series of changes are specific enough to
warrant an actual copy of the steps followed.

And, of course, not all users will have the ability to modify a
template by adding recorded code...

Thanks for the code snipet... I remember doing something with that ID
number, but I didn't think I was successful... I'll try yours.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top