ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Return caption of unknown button into a cell (https://www.excelbanter.com/excel-programming/418850-return-caption-unknown-button-into-cell.html)

PCLIVE

Return caption of unknown button into a cell
 
Is there a way to capture the caption information of a CommandButton that
was just pressed without knowing the name of the CommandButtonand? I'd like
to be able to press a command button (any CommandButton) and have the
caption from that button displayed in, say AA1?

Is there some sort of "ActiveCommandButton" code?
Range("AA1").Value= CaptionOfButtonJustPressed

Is this possible?
Paul



--




Rick Rothstein

Return caption of unknown button into a cell
 
You would have to put the appropriate code in the Click event for each
CommandButton that you want to have this feature... there is no general
overall event (at least not that I am aware of) that can monitor when a
random CommandButton is clicked. Something like this should work...

Private Sub CommandButton1_Click()
Range("AA1").Value = CommandButton1.Caption
End Sub

Private Sub CommandButton2_Click()
Range("AA1").Value = CommandButton2.Caption
End Sub

Private Sub CommandButton3_Click()
Range("AA1").Value = CommandButton3.Caption
End Sub

--
Rick (MVP - Excel)


"PCLIVE" wrote in message
...
Is there a way to capture the caption information of a CommandButton that
was just pressed without knowing the name of the CommandButtonand? I'd
like to be able to press a command button (any CommandButton) and have the
caption from that button displayed in, say AA1?

Is there some sort of "ActiveCommandButton" code?
Range("AA1").Value= CaptionOfButtonJustPressed

Is this possible?
Paul



--






All times are GMT +1. The time now is 04:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com