Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Referring to current control on a worksheet

Many thanks to all for the replies.

Rick - I have adapted your suggestion using the onclick event and it is
working fine.

Richard

"Rick Rothstein" wrote:

Since you said "commandbutton", I'm assuming we are talking about ActiveX
controls, right? Then you can do the following. Create a "global" object
variable (declare it in the General/Declarations section of the worksheet's
code window), set it to the CommandButton (actually, this would work for any
control) in each CommandButton's GotFocus event and clear it again in the
CommandButton's LostFocus event. That way, while the CommandButton is
selected, the global variable will be referencing it. For example...

Dim ActiveControl As Object

Private Sub CommandButton1_GotFocus()
Set ActiveControl = CommandButton1
End Sub

Private Sub CommandButton1_LostFocus()
Set ActiveControl = Nothing
End Sub

Private Sub CommandButton2_GotFocus()
Set ActiveControl = CommandButton2
End Sub

Private Sub CommandButton2_LostFocus()
Set ActiveControl = Nothing
End Sub

You would just need to extend the setup above for all of your
CommandButtons.

--
Rick (MVP - Excel)


"RichardGarfield" wrote in
message ...
I need to be able to refer to the current commandbutton on a worksheet
without specifying the name each time - I have about 25 on each worksheet.

Is there a way of doing this? I have tried 'ActiveControl' but it seems
not
to work on a worksheet.

Please can anyone help?

Richard



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Referring to an ActiveX control Brett Excel Programming 4 May 17th 09 11:20 PM
referring to worksheet Chip Pearson Excel Programming 0 December 1st 06 11:42 PM
referring a worksheet lazmanyak Excel Worksheet Functions 1 July 23rd 05 02:55 PM
referring to other worksheet Geetu M Excel Worksheet Functions 2 March 29th 05 09:37 PM
Can I control Macro run automatically current worksheet? Microlong Excel Programming 2 March 2nd 05 12:39 PM


All times are GMT +1. The time now is 06:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"