+ Reply to Thread
Results 1 to 4 of 4

Get Caption From Userform CommandButton During Click Event Procedure

  1. #1
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Get Caption From Userform CommandButton During Click Event Procedure

    I have a command button and in the ClickEvent code, while it is running, I want to capture the caption of the command button.

    I know I can access it by Me.CommandButton1.Caption and that's what I'm doing and my use of the caption is working perfectly.

    I want to paste the heart of the code into 52 other command buttons and access the caption of each one without having to change the code.

    I found on Ozgrid that I could use ActiveControl, it works if the command button is on a regular form, I've test it.

    These command buttons are on multipages and when I use activecontrol it returns the multipage as the active control.

    There's a property for the command button called TakeFocusOnClick and it's set to True, but that doesn't seem to be helping, for some reason the multipage and not the command button I clicked is considered the active control.

    Any help would be appreciated.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Get Caption From Userform CommandButton During Click Event Procedure

    Try this where MultiPage1 is the name of the multipage object

    Me.MultiPage1.Pages(Me.MultiPage1.Value).ActiveControl.Caption

    Or this...
    ActiveControl.Pages(ActiveControl.Value).ActiveControl.Caption
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Get Caption From Userform CommandButton During Click Event Procedure

    They both work beautifully.
    Thanks.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Get Caption From Userform CommandButton During Click Event Procedure

    You're welcome. Thanks for the reps.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Call a commandbutton click event from a module
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-19-2015, 01:10 PM
  2. Call procedure when I click any commandbutton
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-22-2012, 04:33 AM
  3. Using A Macro To Add Event Procedure To A CommandButton
    By Donna in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-23-2005, 11:06 AM
  4. [SOLVED] Using A Macro To Add Event Procedure To A CommandButton
    By Donna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-21-2005, 11:06 AM
  5. Replies: 1
    Last Post: 02-21-2005, 07:06 AM
  6. [SOLVED] what is right or wrong-Using A Macro To Add Event Procedure To A CommandButton
    By Donna in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2005, 07:58 AM
  7. Programming To The VBE -Using A Macro To Add Event Procedure To A CommandButton
    By DonnaG in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-08-2005, 05:43 PM

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