Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default MouseDown()-MouseUp()


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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default MouseDown()-MouseUp()

Maybe check the state of the mouse periodically during your loop and exit

Private Declare Function GetInputState Lib "user32" () As Long

'in your loop

If GetAsyncKeyState(&H1) Then
' left button is down
Else
' exit code
End If

Regards,
Peter T

"skrol" wrote in
message ...

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default MouseDown()-MouseUp()

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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default MouseDown()-MouseUp()


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

  #5   Report Post  
Posted to microsoft.public.excel.programming
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default MouseDown()-MouseUp()


Thanks...
I did it wrong, but now it's working perfect......

I prefer the second option, stopping the loop on releasing the button.
But your solution is also verey usefull.

Thanks again.

Stoffer Kro

--
skro
-----------------------------------------------------------------------
skrol's Profile: http://www.excelforum.com/member.php...fo&userid=2712
View this thread: http://www.excelforum.com/showthread.php?threadid=47658

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default MouseDown()-MouseUp()

I did it wrong, but now it's working perfect......

Glad you've got it working.

I prefer the second option, stopping the loop on releasing the button.
But your solution is also verey usefull.


I'm a bit confused though -

Both methods should stop the loop when the button is released, are you
saying one of the methods didn't?

My solution was the second of the two examples I posted, if you mean the API
method.

Regards,
Peter T


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
Chart MouseUp Event Feedback Amit Velingkar [MSFT] Charts and Charting in Excel 2 October 26th 09 02:06 AM
mouseup [email protected] Charts and Charting in Excel 2 September 26th 06 05:07 AM
Mousedown / Charting Mark Dawson Excel Programming 0 September 1st 05 08:44 PM
get reference to cell from mousedown event David Excel Programming 3 August 23rd 05 02:00 PM
Converting MouseDown Coordinates to Chart Point Coordinates Steve[_50_] Excel Programming 3 December 2nd 03 06:48 PM


All times are GMT +1. The time now is 10:57 AM.

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"