ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save BeforeClose (https://www.excelbanter.com/excel-programming/442716-save-beforeclose.html)

Seeker

Save BeforeClose
 
Book A has following code to save and close itself and same apply to Book B,
but seems it loops back for book B to close even book B has already been
closed.
Whats wrong with it please?

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
Application.CalculateBeforeSave = False

If Me.Name = "CashFlow.xls" Then
ActiveWorkbook.Save
ActiveWorkbook.SaveCopyAs Filename:="C:\" & Format(Date, "ddmmmyy") &
"A.xls"
Else
End If

Workbooks("B.xls").Save
Workbooks("B.xls").Close

Application.CalculateBeforeSave = True
Application.DisplayAlerts = True


End Sub


ozgrid.com

Save BeforeClose
 
Not sure I understand you, but try adding, as the top line;

Cancel=True
'YOUR CODE



--
Regards
Dave Hawley
www.ozgrid.com
"Seeker" wrote in message
...
Book A has following code to save and close itself and same apply to Book
B,
but seems it loops back for book B to close even book B has already been
closed.
Whats wrong with it please?

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayAlerts = False
Application.CalculateBeforeSave = False

If Me.Name = "CashFlow.xls" Then
ActiveWorkbook.Save
ActiveWorkbook.SaveCopyAs Filename:="C:\" & Format(Date, "ddmmmyy") &
"A.xls"
Else
End If

Workbooks("B.xls").Save
Workbooks("B.xls").Close

Application.CalculateBeforeSave = True
Application.DisplayAlerts = True


End Sub




All times are GMT +1. The time now is 06:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com