ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   stop execution (https://www.excelbanter.com/excel-programming/312226-stop-execution.html)

AL

stop execution
 
2nd post please help
In a form I put a commmandbutton with cancel and
default=true so when the program is running I could stop
the execution, but it does not work, I try click and
mouse-up subs. It only works after the code has finish
executing. What am I doing wrong? Can you give me an
example of how can I accomplish this task?
Thanks in advance
Al
..



Steve Smallman

stop execution
 
Al,

Your code is executing, and during execution, you click on the Cancel
button. Your form is responding to events in the sequence in which they
occur.

Check out the DOEVENTS function.

Steve
"al" wrote in message
...
2nd post please help
In a form I put a commmandbutton with cancel and
default=true so when the program is running I could stop
the execution, but it does not work, I try click and
mouse-up subs. It only works after the code has finish
executing. What am I doing wrong? Can you give me an
example of how can I accomplish this task?
Thanks in advance
Al
.





Bob Kilmer

stop execution
 
What is your code doing that you want to cancel? Is it looping over a range
of values? It would help if you would post an example.

"al" wrote in message
...
2nd post please help
In a form I put a commmandbutton with cancel and
default=true so when the program is running I could stop
the execution, but it does not work, I try click and
mouse-up subs. It only works after the code has finish
executing. What am I doing wrong? Can you give me an
example of how can I accomplish this task?
Thanks in advance
Al
.





Bob Kilmer

stop execution
 
Create a form with two buttons and drop this into its code module.

Option Explicit
Private mCancel As Boolean

Private Sub CommandButton1_Click()
Dim n
Me.MousePointer = fmMousePointerHourGlass
For n = 1 To 10000
'long running process
Debug.Print n
DoEvents
If mCancel = True Then Exit For
Next n
mCancel = False
Me.MousePointer = fmMousePointerDefault
End Sub

Private Sub CommandButton2_Click()
mCancel = True
End Sub

Private Sub UserForm_Initialize()
mCancel = False
End Sub

"al" wrote in message
...
2nd post please help
In a form I put a commmandbutton with cancel and
default=true so when the program is running I could stop
the execution, but it does not work, I try click and
mouse-up subs. It only works after the code has finish
executing. What am I doing wrong? Can you give me an
example of how can I accomplish this task?
Thanks in advance
Al
.






All times are GMT +1. The time now is 02:18 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com