Return caption of unknown button into a cell

P

PCLIVE

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



--
 
R

Rick Rothstein

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top