Consulting

Results 1 to 5 of 5

Thread: Write a Macro to Modify a Macro

  1. #1

    Question Write a Macro to Modify a Macro

    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??

  2. #2
    Moderator VBAX Guru Ken Puls's Avatar
    Joined
    Aug 2004
    Location
    Nanaimo, BC, Canada
    Posts
    4,001
    Location
    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... 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,
    Ken Puls, CMA - Microsoft MVP (Excel)
    I hate it when my computer does what I tell it to, and not what I want it to.

    Learn how to use our KB tags! -||- Ken's Excel Website -||- Ken's Excel Forums -||- My Blog -||- Excel Training Calendar

    This is a shameless plug for my new book "RibbonX - Customizing the Office 2007 Ribbon". Find out more about it here!

    Help keep VBAX clean! Use the 'Thread Tools' menu to mark your own threads solved!





  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    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.

  4. #4
    MZ Tools is great stuff! Thanx guys.

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Yes it is!! For more great add-ins, check out the Resources page.

    Take care!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •