PDA

View Full Version : [SOLVED] Write a Macro to Modify a Macro



Cyberdude
03-22-2005, 11:09 AM
When I write a new macro, I have found it very useful (to me) to do two thiings:
1. Add a comment to the "Sub" line that shows the last date modified, and a list of macros that call this macro.
2. On the "End Sub" line to add a comment that contains the name of the macro. Example:
Sub ClearOldData() '3/22/05 [Called by "Cre8Entry"]
...
End Sub 'ClearOldData'
I'd like to automate this procedure. When I enter the name of a new macro (Sub ClearOldData()), then the editor automatically adds the "End Sub" line. I'd like to take this a step farther, and perform the tasks I mentioned above. I would probably have to write another macro and invoke it, but I have no idea how to write a macro that modifies an existing macro. Am I asking for too much??

Ken Puls
03-22-2005, 11:15 AM
Hmmm...

I'm not 100% sure of this, as I haven't really played much with it, but others on the site swear by MZ Tools (http://www.mztools.com/)... There is a menu item in there to add a procedure header (which you can customize)

It's not exactly what you're asking, but might be worth a boo to see if it's enough. The other could be tricky, although I can't say for sure as I've never tried it.

HTH,

Zack Barresse
03-22-2005, 11:40 AM
MZ Tools is great. I use it almost daily. This can add Module and/or Procedure headers - all of which are comments. It will not, however, update an existing comment. So you can basically stack these comments on top of one another, or write your own VBA to do this.

Cyberdude
03-22-2005, 09:16 PM
MZ Tools is great stuff! Thanx guys.

Zack Barresse
03-22-2005, 09:18 PM
Yes it is!! For more great add-ins, check out the Resources page (http://www.vbaexpress.com/resources.php#Excel).

Take care!