Hi Stoffer,
You'll need a module level variable so that MouseDown & MouseUp event
handlers can share the same variable. You'll also need the DoEvents function
somewhere inside MouseDown's loop to allow the operating system to process
the MouseUp event. The following example should get you going.
Regards,
Vic Eldridge
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
"skrol" wrote:
In one of my sheets I have button, starting a macro wih "MouseDown()".
This macro starts a simple loop.
No problem.
But what I want is that when I release the mouse button, the macto
stops before ending the loop. Now it goes till the end.
Now it's something like this:
Sub CommandButton2_MouseDown()
For i = 1 To 20
Sheets("Plan1").Range("a1").Value = Sheets("Plan1").Range("a1").Value +
1
For j = 1 To 2000
Application.Calculate
Next j
Next i
End Sub
The "j-loop" (For j = 1 To 1000) is only there to slow down the
execution.
Thanks all.
Have a nice sunday.
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