PC Review


Reply
Thread Tools Rate Thread

BeforeClose Event

 
 
LeAnn
Guest
Posts: n/a
 
      19th Mar 2008
Hi,

I have an Excel 2003 template that I need some help with. When the user
opens the template generating an xls file based on the template, I have code
that disables all builtin commandbars and creates a custom one with just a
couple of buttons. On the BeforeClose event I reinstate the builtin commbars
and the custom bar is disabled. Here's the problem. When the user clicks
the application close button, they get the "Do you want to save
changes......" message. The builtin menu gets enabled at that time and if
the user cancels the message, could potentially change the information in the
header/footer through Page Setup. I've tried a few things such as
Application.DisplayAlerts = false (didn't work - still prompts).

When I added ActiveWorkbook.Close SaveChanges:=False, it worked but causes
the user has to click the Application close button 2 times to close Excel.
And, when you re-open Excel afterward the formular bar doesn't appear. See
my code below.

Thanks for your help
LeAnn

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim oCB As CommandBar

On Error Resume Next

ActiveWorkbook.Close SaveChanges:=False

For Each oCB In Application.CommandBars
oCB.Enabled = True
Next oCB

Application.DisplayFormulaBar = True

End Sub

 
Reply With Quote
 
 
 
 
LeAnn
Guest
Posts: n/a
 
      21st Mar 2008
I figured out my own solution. I had to set some boolean variables to detect
what actions the user has taken and allow or disallow other actions.

"LeAnn" wrote:

> Hi,
>
> I have an Excel 2003 template that I need some help with. When the user
> opens the template generating an xls file based on the template, I have code
> that disables all builtin commandbars and creates a custom one with just a
> couple of buttons. On the BeforeClose event I reinstate the builtin commbars
> and the custom bar is disabled. Here's the problem. When the user clicks
> the application close button, they get the "Do you want to save
> changes......" message. The builtin menu gets enabled at that time and if
> the user cancels the message, could potentially change the information in the
> header/footer through Page Setup. I've tried a few things such as
> Application.DisplayAlerts = false (didn't work - still prompts).
>
> When I added ActiveWorkbook.Close SaveChanges:=False, it worked but causes
> the user has to click the Application close button 2 times to close Excel.
> And, when you re-open Excel afterward the formular bar doesn't appear. See
> my code below.
>
> Thanks for your help
> LeAnn
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Dim oCB As CommandBar
>
> On Error Resume Next
>
> ActiveWorkbook.Close SaveChanges:=False
>
> For Each oCB In Application.CommandBars
> oCB.Enabled = True
> Next oCB
>
> Application.DisplayFormulaBar = True
>
> End Sub
>

 
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
BeforeClose Event Yazeed Microsoft Powerpoint 3 20th Jul 2009 01:48 PM
BeforeClose Event problem Jac Tremblay Microsoft Excel Programming 2 12th Jan 2009 02:09 PM
BeforeClose event help azu_daioh@yahoo.com Microsoft Excel Programming 3 22nd Jun 2007 10:02 AM
BeforeClose Event =?Utf-8?B?SlQ=?= Microsoft Excel Programming 2 10th Apr 2007 03:52 PM
problem with beforeclose event Gordon Microsoft Excel Programming 1 30th Sep 2004 11:21 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:00 AM.