Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

BeforeClose Event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
LeAnn - 19 Mar 2008 19:20 GMT
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
LeAnn - 22 Mar 2008 00:10 GMT
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.

> Hi,
>
[quoted text clipped - 31 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.