![]() |
Buttons in Excel VBA
I know that an event is fired when a button is clicked ( Button1_Click() ). I
would like to know if an event is fired when a button is RELEASED. I can't seem to find any information about it. Any help will be appreciated. |
Buttons in Excel VBA
For a Forms Button (from the forms toolbar) the "release" of the button is
actually part of the Click event - if you try this code: Sub Button1_Click() MsgBox "Click!" End Sub you can press and hold in the button with no message, when you release you get "Click!" It is a bit different for the CommandButton from the Controls toolbox: This has 3 events called MouseDown, MouseUp, and Click. They occur in that order. Try creating these 3 Subs: Sub CommandButton1_MouseDown() MsgBox "MouseDown!" End Sub Sub CommandButton1_MouseUp() MsgBox "MouseUp!" End Sub Sub CommandButton1_Click() MsgBox "Click!" End Sub As written, if you press the button you will only see the MouseDown! message. If you erase the MouseDown event procedure you will then see only the MouseUp! message; if you only have the Click procedure you will see - of course - Click! -- - K Dales "misc1111" wrote: I know that an event is fired when a button is clicked ( Button1_Click() ). I would like to know if an event is fired when a button is RELEASED. I can't seem to find any information about it. Any help will be appreciated. |
Buttons in Excel VBA
Hooray !! That code worked great. Thanks for your help.
"K Dales" wrote: For a Forms Button (from the forms toolbar) the "release" of the button is actually part of the Click event - if you try this code: Sub Button1_Click() MsgBox "Click!" End Sub you can press and hold in the button with no message, when you release you get "Click!" It is a bit different for the CommandButton from the Controls toolbox: This has 3 events called MouseDown, MouseUp, and Click. They occur in that order. Try creating these 3 Subs: Sub CommandButton1_MouseDown() MsgBox "MouseDown!" End Sub Sub CommandButton1_MouseUp() MsgBox "MouseUp!" End Sub Sub CommandButton1_Click() MsgBox "Click!" End Sub As written, if you press the button you will only see the MouseDown! message. If you erase the MouseDown event procedure you will then see only the MouseUp! message; if you only have the Click procedure you will see - of course - Click! -- - K Dales "misc1111" wrote: I know that an event is fired when a button is clicked ( Button1_Click() ). I would like to know if an event is fired when a button is RELEASED. I can't seem to find any information about it. Any help will be appreciated. |
All times are GMT +1. The time now is 07:14 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com