Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Disable close unless key held

Hi All,

Is there a way to only enable the close command in excel if the "Shift" key
is held (or any key for that matter) I have a little program that monitors
a computer, but I don't want anyone to close it. (At this time I am not
worried if they kill the process).

Thanks
Chad


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Disable close unless key held

There are several ways to close Excel, 2 ways with the main Excel icon, the
little-x on the main window, Alt-F4, and File/Exit. Only the latter in
2000-2003 can easily be intercepted. To trap the others would require doing
a lot of stuff that's not practical.

A different approach would be to set the Cancel flag in a workbook-close
event if/as required, post back if that might work for your needs.

Regards,
Peter T

"Chad Cameron" remove NOT wrote in message
...
Hi All,

Is there a way to only enable the close command in excel if the "Shift"
key is held (or any key for that matter) I have a little program that
monitors a computer, but I don't want anyone to close it. (At this time I
am not worried if they kill the process).

Thanks
Chad



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Disable close unless key held

I am guessing you mean something like check if ZZ1 = [something] then close.
and then I enter something in that cell when I want to close it.

That will work, its just an extra step.

"Peter T" <peter_t@discussions wrote in message
...
There are several ways to close Excel, 2 ways with the main Excel icon,
the little-x on the main window, Alt-F4, and File/Exit. Only the latter in
2000-2003 can easily be intercepted. To trap the others would require
doing a lot of stuff that's not practical.

A different approach would be to set the Cancel flag in a workbook-close
event if/as required, post back if that might work for your needs.

Regards,
Peter T

"Chad Cameron" remove NOT wrote in message
...
Hi All,

Is there a way to only enable the close command in excel if the "Shift"
key is held (or any key for that matter) I have a little program that
monitors a computer, but I don't want anyone to close it. (At this time
I am not worried if they kill the process).

Thanks
Chad





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Disable close unless key held

No that's not what I meant and not sure how that'd work. Try this in a
ThisWorkbook module and try and close Excel -

Private Declare Function GetKeyState32 Lib "user32" _
Alias "GetKeyState" (ByVal vKey As Integer) As Integer

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim res As Long

res = GetKeyState32(vbKeyControl)

If ThisWorkbook.Saved = False Then
Cancel = (res = 0)
End If

If Cancel Then
MsgBox "hold Ctrl if you want to close Excel"
End If

End Sub

Regards,
Peter T

"Chad Cameron" remove NOT wrote in message
...
I am guessing you mean something like check if ZZ1 = [something] then
close. and then I enter something in that cell when I want to close it.

That will work, its just an extra step.

"Peter T" <peter_t@discussions wrote in message
...
There are several ways to close Excel, 2 ways with the main Excel icon,
the little-x on the main window, Alt-F4, and File/Exit. Only the latter
in 2000-2003 can easily be intercepted. To trap the others would require
doing a lot of stuff that's not practical.

A different approach would be to set the Cancel flag in a workbook-close
event if/as required, post back if that might work for your needs.

Regards,
Peter T

"Chad Cameron" remove NOT wrote in message
...
Hi All,

Is there a way to only enable the close command in excel if the "Shift"
key is held (or any key for that matter) I have a little program that
monitors a computer, but I don't want anyone to close it. (At this time
I am not worried if they kill the process).

Thanks
Chad







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Disable close unless key held

Ok, yes that is what I wanted. I knew I had to use the Cancel Flag, just
wasn't sure how to capture the key
Thanks
Chad

"Peter T" <peter_t@discussions wrote in message
...
No that's not what I meant and not sure how that'd work. Try this in a
ThisWorkbook module and try and close Excel -

Private Declare Function GetKeyState32 Lib "user32" _
Alias "GetKeyState" (ByVal vKey As Integer) As Integer

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim res As Long

res = GetKeyState32(vbKeyControl)

If ThisWorkbook.Saved = False Then
Cancel = (res = 0)
End If

If Cancel Then
MsgBox "hold Ctrl if you want to close Excel"
End If

End Sub

Regards,
Peter T

"Chad Cameron" remove NOT wrote in message
...
I am guessing you mean something like check if ZZ1 = [something] then
close. and then I enter something in that cell when I want to close it.

That will work, its just an extra step.

"Peter T" <peter_t@discussions wrote in message
...
There are several ways to close Excel, 2 ways with the main Excel icon,
the little-x on the main window, Alt-F4, and File/Exit. Only the latter
in 2000-2003 can easily be intercepted. To trap the others would require
doing a lot of stuff that's not practical.

A different approach would be to set the Cancel flag in a workbook-close
event if/as required, post back if that might work for your needs.

Regards,
Peter T

"Chad Cameron" remove NOT wrote in message
...
Hi All,

Is there a way to only enable the close command in excel if the "Shift"
key is held (or any key for that matter) I have a little program that
monitors a computer, but I don't want anyone to close it. (At this
time I am not worried if they kill the process).

Thanks
Chad











  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Disable close unless key held

Actually better to remove the If test altogether

If ThisWorkbook.Saved = False Then

That got left in having tested a slightly different approach

Peter T


"Chad Cameron" remove NOT wrote in message
...
Ok, yes that is what I wanted. I knew I had to use the Cancel Flag, just
wasn't sure how to capture the key
Thanks
Chad

"Peter T" <peter_t@discussions wrote in message
...
No that's not what I meant and not sure how that'd work. Try this in a
ThisWorkbook module and try and close Excel -

Private Declare Function GetKeyState32 Lib "user32" _
Alias "GetKeyState" (ByVal vKey As Integer) As Integer

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim res As Long

res = GetKeyState32(vbKeyControl)

If ThisWorkbook.Saved = False Then
Cancel = (res = 0)
End If

If Cancel Then
MsgBox "hold Ctrl if you want to close Excel"
End If

End Sub

Regards,
Peter T

"Chad Cameron" remove NOT wrote in message
...
I am guessing you mean something like check if ZZ1 = [something] then
close. and then I enter something in that cell when I want to close it.

That will work, its just an extra step.

"Peter T" <peter_t@discussions wrote in message
...
There are several ways to close Excel, 2 ways with the main Excel icon,
the little-x on the main window, Alt-F4, and File/Exit. Only the latter
in 2000-2003 can easily be intercepted. To trap the others would
require doing a lot of stuff that's not practical.

A different approach would be to set the Cancel flag in a
workbook-close event if/as required, post back if that might work for
your needs.

Regards,
Peter T

"Chad Cameron" remove NOT wrote in message
...
Hi All,

Is there a way to only enable the close command in excel if the
"Shift" key is held (or any key for that matter) I have a little
program that monitors a computer, but I don't want anyone to close it.
(At this time I am not worried if they kill the process).

Thanks
Chad











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
How to disable close button in userform? [email protected] Excel Programming 0 February 20th 08 03:53 PM
Disable Close all Windows rjvega Excel Discussion (Misc queries) 1 November 7th 06 03:23 PM
Disable Close All LoDawg Excel Programming 1 November 7th 06 12:32 AM
Disable Close Button dan Excel Discussion (Misc queries) 5 September 22nd 06 07:39 PM
disable close if conditions are not met Michelle K Excel Programming 4 March 16th 05 01:21 PM


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