+ Reply to Thread
Results 1 to 5 of 5

Return the control name of command button just clicked

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Return the control name of command button just clicked

    The Command Button needs to have .TakeFocusOnClick set to True

    Please Login or Register  to view this content.
    Last edited by mc84excel; 03-24-2015 at 07:53 PM.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Return the control name of command button just clicked

    Wouldn't you need to loop or recurse for a control in a frame in a frame in a frame ...?
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Return the control name of command button just clicked

    Quote Originally Posted by shg View Post
    Wouldn't you need to loop or recurse for a control in a frame in a frame in a frame ...?
    True, but I had considered the possibility of a scenario similar to this and dismissed it as being highly unlikely to occur (well for me anyway!)

    If anyone wants to add a loop to the function (or make it recursive), go ahead and I'll credit you.


    Difficult but not impossible IMO. I had given it brief amount of thought - For each lower level, you could test whether it returns Frame or MultiPage type and respond accordingly. If returns anything else, assume it's the 'end of the line' and grab the name. You could use object and On Error Resume Next and Err.Number <> 0

  4. #4
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Return the control name of command button just clicked

    Here's the loop version. I've tested it on a control in a frame in a frame in a frame. It works.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Return the control name of command button just clicked

    Here's something similar, this returns the control object instead of it's name

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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. [SOLVED] How to make a Command button run the "FORM" command to fill/populate a table?
    By jrobin7 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-21-2012, 12:26 PM
  2. Form - Command Button
    By shugg24 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-27-2010, 09:28 AM
  3. Command button is not working by using VBA
    By Webtekr in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2009, 02:22 AM
  4. VB's Command Button vs Form's Command Button
    By Ronald Dodge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2006, 09:30 AM
  5. command button isn't working
    By Nydia in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-29-2005, 06:06 PM

Tags for this Thread

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