Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default close application when interrupt by user

How to close the application without saving the changes when user press
"Ctrl" and "Break" button to interrupt the macro during code running?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default close application when interrupt by user

Terry,
Basically you can't. If the user has interrupted code, how are you going run
code ?

Maybe you need Application.EnableCancelKey

NickHK

"Terry" wrote in message
...
How to close the application without saving the changes when user press
"Ctrl" and "Break" button to interrupt the macro during code running?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 193
Default close application when interrupt by user

I want to invoke some procedure to close the file when user do it.

Application.OnKey "^{BREAK}", "CloseFile"

Sub CloseFile()
ActiveWorkbook.Close savechanges = False
End Sub

But the problem is where I should put the code? as "on error" method will
keep monitor the errors when code running. hoe does "OnKey" works?

"NickHK" wrote:

Terry,
Basically you can't. If the user has interrupted code, how are you going run
code ?

Maybe you need Application.EnableCancelKey

NickHK

"Terry" wrote in message
...
How to close the application without saving the changes when user press
"Ctrl" and "Break" button to interrupt the macro during code running?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default close application when interrupt by user

Terry,
I would be surprised if Excel can work like that, because if code is
executing (which must be the case if the user presses ^BREAK), your code
cannot run.
I suppose that's why your have the .EnableCancelKey property.
You can achieve your goal if you set it to = xlErrorHandler ?
See the help for an example.

NickHK

"Terry" wrote in message
...
I want to invoke some procedure to close the file when user do it.

Application.OnKey "^{BREAK}", "CloseFile"

Sub CloseFile()
ActiveWorkbook.Close savechanges = False
End Sub

But the problem is where I should put the code? as "on error" method will
keep monitor the errors when code running. hoe does "OnKey" works?

"NickHK" wrote:

Terry,
Basically you can't. If the user has interrupted code, how are you going

run
code ?

Maybe you need Application.EnableCancelKey

NickHK

"Terry" wrote in message
...
How to close the application without saving the changes when user

press
"Ctrl" and "Break" button to interrupt the macro during code running?






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default close application when interrupt by user

Hi Nick,

Can you expand on the .EnableCancelKey property, and the solution you gave
to Terry? This sounds like something I could really have a use for.

Thanks,

Alan

"NickHK" wrote:

Terry,
I would be surprised if Excel can work like that, because if code is
executing (which must be the case if the user presses ^BREAK), your code
cannot run.
I suppose that's why your have the .EnableCancelKey property.
You can achieve your goal if you set it to = xlErrorHandler ?
See the help for an example.

NickHK

"Terry" wrote in message
...
I want to invoke some procedure to close the file when user do it.

Application.OnKey "^{BREAK}", "CloseFile"

Sub CloseFile()
ActiveWorkbook.Close savechanges = False
End Sub

But the problem is where I should put the code? as "on error" method will
keep monitor the errors when code running. hoe does "OnKey" works?

"NickHK" wrote:

Terry,
Basically you can't. If the user has interrupted code, how are you going

run
code ?

Maybe you need Application.EnableCancelKey

NickHK

"Terry" wrote in message
...
How to close the application without saving the changes when user

press
"Ctrl" and "Break" button to interrupt the macro during code running?









  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default close application when interrupt by user

Alan,
Whilst I would not necessarily advise closing/quitting in such a suitable,
you can decide what to do:

Private Sub CommandButton1_Click()
Dim i As Long
Dim j As Long

Application.EnableCancelKey = xlErrorHandler
On Error GoTo Handler

For i = 1 To 100000
For j = 1 To 10000
Debug.Print "Value=: " & i * j
Next
DoEvents
Next

Exit Sub

Handler:
'Either an error or the code has been stopped
MsgBox "You are in the handler." & vbNewLine & "Exiting routine."

'Do what you want
End Sub

NickHK

"Alan Smith" wrote in message
...
Hi Nick,

Can you expand on the .EnableCancelKey property, and the solution you gave
to Terry? This sounds like something I could really have a use for.

Thanks,

Alan

"NickHK" wrote:

Terry,
I would be surprised if Excel can work like that, because if code is
executing (which must be the case if the user presses ^BREAK), your code
cannot run.
I suppose that's why your have the .EnableCancelKey property.
You can achieve your goal if you set it to = xlErrorHandler ?
See the help for an example.

NickHK

"Terry" wrote in message
...
I want to invoke some procedure to close the file when user do it.

Application.OnKey "^{BREAK}", "CloseFile"

Sub CloseFile()
ActiveWorkbook.Close savechanges = False
End Sub

But the problem is where I should put the code? as "on error" method

will
keep monitor the errors when code running. hoe does "OnKey" works?

"NickHK" wrote:

Terry,
Basically you can't. If the user has interrupted code, how are you

going
run
code ?

Maybe you need Application.EnableCancelKey

NickHK

"Terry" wrote in message
...
How to close the application without saving the changes when user

press
"Ctrl" and "Break" button to interrupt the macro during code

running?









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
Don't let user close. Use macro button to close? mike Excel Programming 2 October 30th 06 01:31 PM
Runtime error 18 user interrupt occured on some Computers Felix Excel Programming 1 October 3rd 06 10:21 PM
difference application.quit & application.close Pierre via OfficeKB.com[_2_] Excel Programming 4 November 8th 05 07:55 PM
macro to close excel application other than application.quit mary Excel Programming 1 September 14th 04 03:43 PM
how to prevent user to interrupt macro Jerome LT Excel Programming 2 August 13th 03 10:28 AM


All times are GMT +1. The time now is 10:22 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"