+ Reply to Thread
Results 1 to 4 of 4

Code to rationalise multiple command buttons in VBA

  1. #1
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Code to rationalise multiple command buttons in VBA

    Hi there

    Would anybody be able to advise me on my problem?

    I have 63 command buttons on a userform in multipage controls. Each command button, when clicked, does almost the same thing. For example:

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    and so on. Is there a way to create a sub which will recognise the name of the command button, eg 2_1_1 for cmd 2_1_1 and 2_1_2 for cmd2_1_2 so that I can call that sub to execute the code? There is a different caption name for each button.

    Thanks all.

  2. #2
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Re: Code to rationalise multiple command buttons in VBA

    Any thoughts? I wonder if an event handler is the answer. Help!

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Code to rationalise multiple command buttons in VBA

    I'd create an Event Handler because I couldn't be bothered adding code to each command button, but if you don't feel comfortable with classes, you might get away with something like:

    Please Login or Register  to view this content.
    If you're interested, the event handler class would look something like:

    Class CbtnHandler:
    Please Login or Register  to view this content.
    Form implementation:
    Please Login or Register  to view this content.
    This approach would need no code in the button click subs
    Last edited by Kyle123; 11-16-2012 at 07:24 AM.

  4. #4
    Forum Contributor
    Join Date
    07-23-2012
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    211

    Re: Code to rationalise multiple command buttons in VBA

    Wow! When am I going to get to this level of understanding! (probably never...)

    Kyle, thanks for these options. I will try them out.

+ 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