Can anyone provide a code snippet for capturing the text on a command button? I need to paste the text to a cell. Thanks in advance!
Can anyone provide a code snippet for capturing the text on a command button? I need to paste the text to a cell. Thanks in advance!
Something like this perhaps.
![]()
Please Login or Register to view this content.
Assuming the command buttion is named CommandButton1. If you need to paste it in a cell it would just be:
edit: got beat![]()
Please Login or Register to view this content.
[QUOTE=stnkynts;2998700]Assuming the command buttion is named CommandButton1. If you need to paste it in a cell it would just be:
Thanks! Do you know of a way to do this without knowing the button's name? I'm trying to develop a single macro to work on hundreds of buttons (I also don't want hundreds of macros). For instance, is there a way for the macro to know which button it is by the fact it was just pushed?![]()
Please Login or Register to view this content.
cadnauseam
I think we need some more information.
Where are the 100s of command buttons located?
Why do you want to capture their caption?
I have a sheet with hundreds of parts catalogued, with descriptions, part numbers, and an image for each. Under each image is a cell with the name of the part. And under that cell is one with a command button. I want the user to click on this button, and have the name of the part copied to Sheet 1, cell A1. An external program will read this cell. I could hardcode the part name into each macro, but I was trying to avoid having so many unique macros.
I looked at a way to have the macro read the part name, but couldn't make that work. See:
http://www.excelforum.com/excel-prog...23#post2997423
It will take more time to create some fancy macro, if at all possible, than it would take to put in one line of code for 100 command buttons. Just copy/paste and change the command button name.
Thanks for responding. You're right about the time factor, but it's worth it to me to investigate a bit more for the right solution because the scope of this project is going to grow. What is a hundred now could easily become a thousand. Although at that point I will have to look at breaking it up into different pieces based on categories, and design some kind of front end for it.
Last edited by cadnauseum; 11-07-2012 at 05:52 PM. Reason: typo
cadnauseam
Can you attach a small sample workbook to demonstrate what you want to do?
There might be other approachs that can be taken to achieve it.
This code will get the corresponding image name when the a button is pressed.
It kind of relies on your current layout with the button in the cell below the image name.
![]()
Please Login or Register to view this content.
If posting code please use code tags, see here.
Can the string be written directly to Sheet1, Cell A1 , without popping up the message box?
You can do anything you want with the string - the messagebox is just to show the code works.
![]()
Please Login or Register to view this content.
@ Norie,
Nice one!![]()
Please consider:
Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks