Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to detect user quitting excel

I have an application using several open workbooks. I need to detec
when a user tries to close Excel without going through my menu. i.e
clicking on the 'X'.
Our IT department will not allow adding DLL's to the system so I need
subclassing skeleton source or any other source-based answer.

Thank yo

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 93
Default How to detect user quitting excel

Excel, unlike Word, does not have an onQuit event. So, your application cannot know whether Excel has terminated via an event

You could use FindWindow

When you create the instance of Excel, change its caption to something unique. Use this caption to find the handle of the Windows session. Do everything that you make Excel do ..
In your code, keep checking whether the Excel handle still exists: if it does, Excel is still in use. PROBLEM: Excel could still be active but have no active workbook

Why do you need to know whether Excel is being terminated?
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 94
Default How to detect user quitting excel

Here is one approach. You can use a class module to create Application-Level
events. There is an event called "WorkbookBeforeClose" which traps when the
user attempts to close ANY of the open workbooks. If the user clicks the Red
X, this event should be triggered. FYI, there are many other
Application-Level events that can be programmed also.

The events will not be active until they are initialized by the
"Initialize_XL_App_Events" subroutine. I've placed that routine in the
"Workbook_Open" event which is triggered when the workbook is first opened,
provided the user enables macros.

Troy


1) Insert a Class Module in the Excel VBE
2) Rename the Class Module: cls_xlAppEvents
3) Place the following code in the class module codepane.
'===== Class Module Codepane =============================
Option Explicit

Private WithEvents xlApp As Application

Private Sub Class_Initialize()
Set xlApp = Excel.Application
End Sub

Private Sub xlApp_WorkbookBeforeClose(ByVal Wb As Workbook, Cancel As
Boolean)
'Place your code of how you want to handle BeforeClose
'for any excel workbook in this session here.
MsgBox "You are not allowed to close the workbook"

'Cancel=True, cancels the user's attempt to close the workbook.
Cancel = True
End Sub
'================================================= ===


4) Insert a standard module
5) Place the following code in the codepane
'===== Standard Module Codepane ===========================
Option Explicit

Dim xlAppEvents As cls_xlAppEvents

Sub Initialize_XL_App_Events()
'Must run this routine when the Excel Application
'first starts to sink the events.
Set xlAppEvents = New cls_xlAppEvents
End Sub
'================================================= ===


6) Open the ThisWorkbook codepane
7) Place the following code in the codepane
'===== ThisWorkbook Codepane ============================
Option Explicit

Private Sub Workbook_Open()
'Initialize the application level events.
Initialize_XL_App_Events
End Sub
'================================================= ===

"danzel " wrote in message
...
I have an application using several open workbooks. I need to detect
when a user tries to close Excel without going through my menu. i.e.
clicking on the 'X'.
Our IT department will not allow adding DLL's to the system so I need a
subclassing skeleton source or any other source-based answer.

Thank you


---
Message posted from http://www.ExcelForum.com/



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 can I detect if user is in Group Mode when a macro starts? R-N Excel Programming 5 June 15th 04 01:16 PM
Problem quitting excel when it is used by ASP.NET application Tom Excel Programming 0 May 10th 04 08:35 PM
how to detect if user has a dialogbox open Von Shean Excel Programming 2 January 12th 04 02:35 PM
Quitting Excel without saving manishc[_2_] Excel Programming 1 November 16th 03 11:55 AM
Quitting a User Form Bob Kaku Excel Programming 1 August 15th 03 08:46 PM


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