PC Review


Reply
Thread Tools Rate Thread

close application when interrupt by user

 
 
=?Utf-8?B?VGVycnk=?=
Guest
Posts: n/a
 
      7th Dec 2006
How to close the application without saving the changes when user press
"Ctrl" and "Break" button to interrupt the macro during code running?

 
Reply With Quote
 
 
 
 
NickHK
Guest
Posts: n/a
 
      7th Dec 2006
Terry,
Basically you can't. If the user has interrupted code, how are you going run
code ?

Maybe you need Application.EnableCancelKey

NickHK

"Terry" <(E-Mail Removed)> wrote in message
news:B698F902-BF25-49CA-8D96-(E-Mail Removed)...
> How to close the application without saving the changes when user press
> "Ctrl" and "Break" button to interrupt the macro during code running?
>



 
Reply With Quote
 
=?Utf-8?B?VGVycnk=?=
Guest
Posts: n/a
 
      7th Dec 2006
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" <(E-Mail Removed)> wrote in message
> news:B698F902-BF25-49CA-8D96-(E-Mail Removed)...
> > How to close the application without saving the changes when user press
> > "Ctrl" and "Break" button to interrupt the macro during code running?
> >

>
>
>

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      7th Dec 2006
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" <(E-Mail Removed)> wrote in message
news:B8049796-23A3-433A-A5A1-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> > news:B698F902-BF25-49CA-8D96-(E-Mail Removed)...
> > > How to close the application without saving the changes when user

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

> >
> >
> >



 
Reply With Quote
 
=?Utf-8?B?QWxhbiBTbWl0aA==?=
Guest
Posts: n/a
 
      28th May 2007
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" <(E-Mail Removed)> wrote in message
> news:B8049796-23A3-433A-A5A1-(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > > news:B698F902-BF25-49CA-8D96-(E-Mail Removed)...
> > > > How to close the application without saving the changes when user

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

>
>
>

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      29th May 2007
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" <(E-Mail Removed)> wrote in message
news:EFFF603E-6CED-4A2D-8609-(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> > news:B8049796-23A3-433A-A5A1-(E-Mail Removed)...
> > > 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" <(E-Mail Removed)> wrote in message
> > > > news:B698F902-BF25-49CA-8D96-(E-Mail Removed)...
> > > > > How to close the application without saving the changes when user

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

running?
> > > > >
> > > >
> > > >
> > > >

> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to interrupt a form close? LAS Microsoft Access Form Coding 5 17th Aug 2010 10:39 PM
Word on close, 'normal.dot is used by another application or user' =?Utf-8?B?VG90byBTYW5kZXJzb24=?= Microsoft Word Document Management 1 2nd Jun 2006 09:15 PM
TS hangs when user close the only application permited =?Utf-8?B?TGFuem9uaQ==?= Microsoft Windows 2000 Terminal Server Applications 3 16th Jun 2005 09:12 PM
How to NOT allow a user to close an application? Carey Frisch [MVP] Windows XP Security 2 6th Feb 2005 06:44 PM
Keep user from exiting application via close button charles Windows XP Security 6 9th Jan 2004 12:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:35 PM.