Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Workbook Close Event

Hello,
I have code as follows in "Thisworkbook" codesheet:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Quitting As Integer
Dim wb As Workbook
Dim ws As Worksheet
With Application
If .Workbooks.Count 1 Then
For Each wb In .Workbooks
If wb.Name = ThisWorkbook.Name Then
'do nothing
Else
.EnableEvents = False
wb.Close False
.EnableEvents = True
End If
Next
End If
.ScreenUpdating = True
.ScreenUpdating = False
End With
Quitting = MsgBox("Save changes?", vbQuestion + vbYesNoCancel, "Cost
Distribution")
Application.ScreenUpdating = False
Select Case Quitting
Case vbYes
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "Sheet*" Then
ws.Delete
End If
Next
ActiveWorkbook.Save
Case vbNo
ThisWorkbook.Saved = True
Case vbCancel
Cancel = True
Exit Sub
End Select
RestoreEnvironment
Application.DisplayAlerts = False
Application.Caption = Empty
Application.Quit
End Sub

It works fine when only the workbook with the code is open and closed.
However if other workbooks are opened and closed, firing the close event,
the procedure hangs not allowing Excel to quit. I have tried variations of
this code to no avail.
Any suggestions?

Regards,
Stefano Condotta


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default Workbook Close Event

Hi
have tested your code under Excel 97 and 2003 and it works for me (you
have some screenupdating statements in your code which are not
necessary but that's not a problem).
Have you tried stepping through your code with a debugger (setting a
breakpoint in your Before_close event?.
Maybe you can than identify at which point your code hangs.

--
Regards
Frank Kabel
Frankfurt, Germany


Stefano Condotta wrote:
Hello,
I have code as follows in "Thisworkbook" codesheet:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim Quitting As Integer
Dim wb As Workbook
Dim ws As Worksheet
With Application
If .Workbooks.Count 1 Then
For Each wb In .Workbooks
If wb.Name = ThisWorkbook.Name Then
'do nothing
Else
.EnableEvents = False
wb.Close False
.EnableEvents = True
End If
Next
End If
.ScreenUpdating = True
.ScreenUpdating = False
End With
Quitting = MsgBox("Save changes?", vbQuestion +
vbYesNoCancel, "Cost Distribution")
Application.ScreenUpdating = False
Select Case Quitting
Case vbYes
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Worksheets
If ws.Name Like "Sheet*" Then
ws.Delete
End If
Next
ActiveWorkbook.Save
Case vbNo
ThisWorkbook.Saved = True
Case vbCancel
Cancel = True
Exit Sub
End Select
RestoreEnvironment
Application.DisplayAlerts = False
Application.Caption = Empty
Application.Quit
End Sub

It works fine when only the workbook with the code is open and
closed. However if other workbooks are opened and closed, firing the
close event, the procedure hangs not allowing Excel to quit. I have
tried variations of this code to no avail.
Any suggestions?

Regards,
Stefano Condotta


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
captcure close application event suru Excel Worksheet Functions 2 June 17th 09 07:10 AM
Workbook-Close StopTimer event Stonewall Rubberbow Excel Discussion (Misc queries) 2 January 12th 08 11:06 PM
before close event with condition mohavv Excel Discussion (Misc queries) 4 November 21st 07 03:14 AM
Clear Clipboard on Workbook Close Event (Excel XP) Culichi Excel Programming 2 February 23rd 04 06:21 PM
After Close Event? Don Wiss Excel Programming 2 November 19th 03 12:30 AM


All times are GMT +1. The time now is 03:21 PM.

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"