+ Reply to Thread
Results 1 to 7 of 7

Question about creating code through a routine

  1. #1
    Registered User
    Join Date
    10-29-2006
    Posts
    7

    Question about creating code through a routine

    Hi,

    I'm trying to set something up, so that every time a routine is called, it creates a new CommandButton and automatically creates a CommandButtonX_Click Sub with the same code. For example, the first time the button is clicked, it creates CommandButton9 and creates code like this:

    Private Sub CommandButton9_Click()
    Call MySub
    End Sub

    The next time it would create CommandButton10, etc.

    Does anyone know if this is possible? If so, how would I do it?


    Thanks,
    Chris

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Chris,

    Chip Pearson has all the info on his site...
    http://www.cpearson.com/excel/vbe.htm

    Sincerely,
    Leith Ross

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    Something like this should work
    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Caligula83

    Please wrap your VBA code - see red link below for instructions

    Please also read forum rules - see blue link below
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  5. #5
    Registered User
    Join Date
    10-29-2006
    Posts
    7
    Thanks for your help. This does create a button, but not the normal CommandButton I'm looking for (i.e. I can't use the VBA design toolbar to modify its properties, like color, font, etc.). Ideally, I'd like to be able to have more than one button visible as well... I'm lost as to how to do this. Suggestions?

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Caligula83,

    There are 2 toolbars from which you can create buttons Forms and Control Toolbox. Which one did you use?

    Sincerely,
    Leith Ross

  7. #7
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    Closing thread

    Caligula83

    did not wrap VBA code as requested to do so

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1