PC Review


Reply
Thread Tools Rate Thread

Application.Quit in Excel 2007

 
 
=?Utf-8?B?UGF1bCBELg==?=
Guest
Posts: n/a
 
      31st May 2007
I want to force users to close the Excel Application using a CloseButton on a
UserForm rather than the X button, so I have the following code:

In the ThisWorkbook Module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If CloseMode = vbFormControlMenu Then
Cancel = True
Open_Switchboard 'name of UserForm
End If
End Sub

In the Userform:

Private Sub cmdCloseButton_Click()
Application.Quit
End Sub

When I click the CloseButton on the UserForm, nothing happens. If I remove
the code from "Private Sub Workbook_BeforeClose(Cancel As Boolean)" then the
application quits when I click the CloseButton.

Why is that? Is this a bug in Excel 2007? Any help?


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGF1bCBELg==?=
Guest
Posts: n/a
 
      31st May 2007
This application is saved in "Compatibility Mode" if that makes any difference.
I searched Excel 2007 Help file for "CloseMode", nothing in help.

"Paul D." wrote:

> I want to force users to close the Excel Application using a CloseButton on a
> UserForm rather than the X button, so I have the following code:
>
> In the ThisWorkbook Module:
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> If CloseMode = vbFormControlMenu Then
> Cancel = True
> Open_Switchboard 'name of UserForm
> End If
> End Sub
>
> In the Userform:
>
> Private Sub cmdCloseButton_Click()
> Application.Quit
> End Sub
>
> When I click the CloseButton on the UserForm, nothing happens. If I remove
> the code from "Private Sub Workbook_BeforeClose(Cancel As Boolean)" then the
> application quits when I click the CloseButton.
>
> Why is that? Is this a bug in Excel 2007? Any help?
>
>

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      31st May 2007
Paul,
IIRC, CloseMode is only valid on a userform. It is not supported on the
Excel app - unless that has changed in XL2007.
This approach will not work.

Maybe setting a flag when the userform unload and call application.quit.
In the Workbook_BeforeClose, check the value of the flag and set
cancel=True/false.

NickHK

"Paul D." <(E-Mail Removed)> 级糶秎ン穝籇:8CF2AC6D-FDCB-4DC8-A1BA-(E-Mail Removed)...
>I want to force users to close the Excel Application using a CloseButton on
>a
> UserForm rather than the X button, so I have the following code:
>
> In the ThisWorkbook Module:
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> If CloseMode = vbFormControlMenu Then
> Cancel = True
> Open_Switchboard 'name of UserForm
> End If
> End Sub
>
> In the Userform:
>
> Private Sub cmdCloseButton_Click()
> Application.Quit
> End Sub
>
> When I click the CloseButton on the UserForm, nothing happens. If I remove
> the code from "Private Sub Workbook_BeforeClose(Cancel As Boolean)" then
> the
> application quits when I click the CloseButton.
>
> Why is that? Is this a bug in Excel 2007? Any help?
>
>



 
Reply With Quote
 
=?Utf-8?B?UGF1bCBELg==?=
Guest
Posts: n/a
 
      31st May 2007
Thanks NickHK
I tried Public Ok2Close as Boolean at the module level.
In a procedure I wrote:
Ok2Close = True
Application.Quit

The first line in: Private Sub Workbook_BeforeClose(Cancel As Boolean)
Debug.Print Ok2Close

the value of Ok2Close is always False

The variable Ok2Close looses its set value between the Module and
ThisWorkbook. Can't figure out why.
"NickHK" wrote:

> Paul,
> IIRC, CloseMode is only valid on a userform. It is not supported on the
> Excel app - unless that has changed in XL2007.
> This approach will not work.
>
> Maybe setting a flag when the userform unload and call application.quit.
> In the Workbook_BeforeClose, check the value of the flag and set
> cancel=True/false.
>
> NickHK
>
> "Paul D." <(E-Mail Removed)> 录露录g漏贸露l楼贸路s禄D:8CF2AC6D-FDCB-4DC8-A1BA-(E-Mail Removed)...
> >I want to force users to close the Excel Application using a CloseButton on
> >a
> > UserForm rather than the X button, so I have the following code:
> >
> > In the ThisWorkbook Module:
> >
> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > If CloseMode = vbFormControlMenu Then
> > Cancel = True
> > Open_Switchboard 'name of UserForm
> > End If
> > End Sub
> >
> > In the Userform:
> >
> > Private Sub cmdCloseButton_Click()
> > Application.Quit
> > End Sub
> >
> > When I click the CloseButton on the UserForm, nothing happens. If I remove
> > the code from "Private Sub Workbook_BeforeClose(Cancel As Boolean)" then
> > the
> > application quits when I click the CloseButton.
> >
> > Why is that? Is this a bug in Excel 2007? Any help?
> >
> >

>
>
>

 
Reply With Quote
 
NickHK
Guest
Posts: n/a
 
      1st Jun 2007
Paul,
It sounds like it's a question of SCOPE.

Declare the variable Public in a standard module, not on the worksheet
module, or call it with
Sheet2.Ok2Close = True

NickHK

"Paul D." <(E-Mail Removed)> wrote in message
news:92B888FA-69C3-4BAF-ADDA-(E-Mail Removed)...
> Thanks NickHK
> I tried Public Ok2Close as Boolean at the module level.
> In a procedure I wrote:
> Ok2Close = True
> Application.Quit
>
> The first line in: Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Debug.Print Ok2Close
>
> the value of Ok2Close is always False
>
> The variable Ok2Close looses its set value between the Module and
> ThisWorkbook. Can't figure out why.
> "NickHK" wrote:
>
> > Paul,
> > IIRC, CloseMode is only valid on a userform. It is not supported on the
> > Excel app - unless that has changed in XL2007.
> > This approach will not work.
> >
> > Maybe setting a flag when the userform unload and call application.quit.
> > In the Workbook_BeforeClose, check the value of the flag and set
> > cancel=True/false.
> >
> > NickHK
> >
> > "Paul D." <(E-Mail Removed)>

级糶秎ン穝籇:8CF2AC6D-FDCB-4DC8-A1BA-(E-Mail Removed)...
> > >I want to force users to close the Excel Application using a

CloseButton on
> > >a
> > > UserForm rather than the X button, so I have the following code:
> > >
> > > In the ThisWorkbook Module:
> > >
> > > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > > If CloseMode = vbFormControlMenu Then
> > > Cancel = True
> > > Open_Switchboard 'name of UserForm
> > > End If
> > > End Sub
> > >
> > > In the Userform:
> > >
> > > Private Sub cmdCloseButton_Click()
> > > Application.Quit
> > > End Sub
> > >
> > > When I click the CloseButton on the UserForm, nothing happens. If I

remove
> > > the code from "Private Sub Workbook_BeforeClose(Cancel As Boolean)"

then
> > > the
> > > application quits when I click the CloseButton.
> > >
> > > Why is that? Is this a bug in Excel 2007? Any help?
> > >
> > >

> >
> >
> >



 
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
Application.Quit Not Working in Office 2007 Carl Microsoft Excel Programming 8 2nd Jun 2009 09:21 AM
Excel.Application.Quit Bob B. Microsoft Access VBA Modules 2 3rd Apr 2008 05:36 PM
Excel.Application.Quit() Mircea Pleteriu Microsoft Excel Programming 1 8th Mar 2005 03:03 PM
Excel application does not quit Gena Microsoft Excel Programming 0 29th Oct 2004 06:17 PM
macro to close excel application other than application.quit mary Microsoft Excel Programming 1 14th Sep 2004 03:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:07 PM.