Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
abort macro dialog box
Thanks for your verry quick respond.
I found somthing in the helpfile and made som buttons to it. So this is the code i intergrated in it: On Error GoTo handleCancel Application.EnableCancelKey = xlErrorHandler For X = 1 To 1000000 ' Do something 1,000,000 times (long!) ' do something here Next X handleCancel: If Err = 18 Then If MsgBox("Do you want to quit?", vbYesNo) = vbYes Then Exit Sub Else Resume End If End If But thing i dont like when i say "NO" He start running the macro from the beginning, and not from the point i interupt him. Can this be doen or is that just impossible? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
abort macro dialog box
Chris
Your code is fine exept that you need to put Exit Sub just before your error handler to stop the code running in to your error handler code as this can cause some strange looping effects (from bitter experience) The resume statement will carry on execution at the point the error was thrown (i.e. when cancel is pressed) so I'm confused as to my it would start from the beginning again. I ran your code and just added application.statusbar = x in the Loop and when I press cancel it resumes at the point I pressed cancel. Try adding this code and see what happens. If you still getting the error then post your live code and I'll have a look at it. Nick "Chris" wrote in message om... Thanks for your verry quick respond. I found somthing in the helpfile and made som buttons to it. So this is the code i intergrated in it: On Error GoTo handleCancel Application.EnableCancelKey = xlErrorHandler For X = 1 To 1000000 ' Do something 1,000,000 times (long!) ' do something here Next X handleCancel: If Err = 18 Then If MsgBox("Do you want to quit?", vbYesNo) = vbYes Then Exit Sub Else Resume End If End If But thing i dont like when i say "NO" He start running the macro from the beginning, and not from the point i interupt him. Can this be doen or is that just impossible? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
abort macro dialog box
Have you tried Resume Next statement?
"Chris" wrote: Thanks for your verry quick respond. I found somthing in the helpfile and made som buttons to it. So this is the code i intergrated in it: On Error GoTo handleCancel Application.EnableCancelKey = xlErrorHandler For X = 1 To 1000000 ' Do something 1,000,000 times (long!) ' do something here Next X handleCancel: If Err = 18 Then If MsgBox("Do you want to quit?", vbYesNo) = vbYes Then Exit Sub Else Resume End If End If But thing i dont like when i say "NO" He start running the macro from the beginning, and not from the point i interupt him. Can this be doen or is that just impossible? |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
abort macro dialog box
Another possibility is:
On Error Resume Next Application.EnableCancelKey = xlErrorHandler For X = 1 To 1000000 ' Do something 1,000,000 times (long!) ' do something here If Err = 18 Then If MsgBox("Do you want to quit?", vbYesNo) = vbYes Then Exit Sub Err = 0 End If Next X "Chris" wrote: Thanks for your verry quick respond. I found somthing in the helpfile and made som buttons to it. So this is the code i intergrated in it: On Error GoTo handleCancel Application.EnableCancelKey = xlErrorHandler For X = 1 To 1000000 ' Do something 1,000,000 times (long!) ' do something here Next X handleCancel: If Err = 18 Then If MsgBox("Do you want to quit?", vbYesNo) = vbYes Then Exit Sub Else Resume End If End If But thing i dont like when i say "NO" He start running the macro from the beginning, and not from the point i interupt him. Can this be doen or is that just impossible? |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
abort macro dialog box
Thanks for your help guys. Since I have a protected sheet i made a 'goto' istead of 'exit sub'(in the code you'll see why). If the problem is there can you please give me the exact place where to put that sentence, i tried several places but it won't work. I have tried charlies code aswell but when i hit the 'Esc' button he just stops and don't even come with the message box. I have a progress bar in my macro, who start counting again, when I say 'NO'. So maybe it is just the progress bar who start couting again, while the macro just go further..... I'll have to look at that, but i'm verry new in VBA so that will take som time. When i found out whether it is just only the progress bar or the whole macro i'll let you guys know. Thanks so far. *** Sent via Developersdex http://www.developersdex.com *** |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
abort macro dialog box
Hey guys,
Again thanks for your help. I just looked again to my macro and i made a verry stupid mistake. I had paste the error handler in the commandbutton_sub instead of in the running sub. *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
abort macro dialog box | Excel Programming | |||
control of dialog macro dialog box. on open | Excel Programming | |||
How to abort executing macro? | Excel Programming | |||
Abort or continue | Excel Programming | |||
Abort or continue | Excel Programming |