View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default MouseDown()-MouseUp()

Hi Stoffer Krol,

Afraid I gave you completely the wrong API, not very helpful!

Both Vic's and my (corrected) suggestions should work same way with
Worksheet CommandButtoms.

Put two on a sheet, named CommandButton1 & CommandButton2, and paste
following into the sheet module

Private Declare Function GetAsyncKeyState Lib "User32" _
(ByVal vKey As Long) As Long

Dim MouseIsDown As Boolean


Private Sub CommandButton1_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
MouseIsDown = True
Do While MouseIsDown
Range("A1") = Range("A1") + 1
DoEvents
Loop
End Sub

Private Sub CommandButton1_MouseUp(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
MouseIsDown = False
End Sub


Private Sub CommandButton2_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
DoEvents ' to depress the button
Do While GetAsyncKeyState(&H1)
Range("A2") = Range("A2") + 1
Loop
End Sub

Take your pick!

Regards,
Peter T


"skrol" wrote in
message ...

Thanks Peter and Vic.
Specialy Vic's solution runs perfect in any userform.

But I wanted things going by operating a CommandButton on the sheet.
I'm wrestling with it for almost 1 day, but I can't get it.



Maybe someone knows the (simple I hope) solution.

Stoffer Krol


--
skrol
------------------------------------------------------------------------
skrol's Profile:

http://www.excelforum.com/member.php...o&userid=27126
View this thread: http://www.excelforum.com/showthread...hreadid=476586