Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default "what triggered the event"

I need command buttons on a spreadsheet to change color on
the mouse_down and then back on the mouse_up events. But
rather the writing the code for the mousedown/up event for
each individual button, I want to write two subs (one for
mouse_down and other for mouse_up) that that will be
called by the buttons e.g.

Private Sub Button_Mouse_Down()
"WhichButtonCalledMe".backColor = RGB(255,0,0)
End sub

Private Sub Button_Mouse_Up()
"WhichButtonCalledMe".Backcolor = RGB(0,255,0)
End Sub

How do I find out what button called the subs?
Hope this makes sense to someone out there.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default "what triggered the event"

Hi

This is what Classes do. Insert a class module. Name it MyBtn. Put this code
in it:

Option Explicit

Public WithEvents Btn As MSForms.CommandButton

Private Sub Btn_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Btn.BackColor = RGB(255, 0, 0)
End Sub

Private Sub Btn_MouseUp(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Btn.BackColor = RGB(0, 255, 0)
End Sub

Now in your sheet module put this code:

Option Explicit

Dim B1 As New MyBtn
Dim B2 As New MyBtn
Dim B3 As New MyBtn

Private Sub Worksheet_Activate()
Set B1.Btn = Me.CommandButton1
Set B2.Btn = Me.CommandButton2
Set B3.Btn = Me.CommandButton3
End Sub

You may have to deactivate/reactivate the sheet before it works
properly -Activate probably isn't the best place to assign the class. But
it's a demo, I hope it gets you started in the right direction.

HTH. Best wishes Harald



"Rod Jones" skrev i melding
...
I need command buttons on a spreadsheet to change color on
the mouse_down and then back on the mouse_up events. But
rather the writing the code for the mousedown/up event for
each individual button, I want to write two subs (one for
mouse_down and other for mouse_up) that that will be
called by the buttons e.g.

Private Sub Button_Mouse_Down()
"WhichButtonCalledMe".backColor = RGB(255,0,0)
End sub

Private Sub Button_Mouse_Up()
"WhichButtonCalledMe".Backcolor = RGB(0,255,0)
End Sub

How do I find out what button called the subs?
Hope this makes sense to someone out there.





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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
HELP on "left","right","find","len","substitute" functions serene83 Excel Discussion (Misc queries) 5 June 27th 06 02:23 AM
Count occurences of "1"/"0" (or"TRUE"/"FALSE") in a row w. conditions in the next BCB New Users to Excel 7 May 13th 06 10:02 PM
Make "BeforeSave" event supply a default path and file name? quartz Excel Programming 1 April 22nd 04 08:08 PM


All times are GMT +1. The time now is 11:17 PM.

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

About Us

"It's about Microsoft Excel"