From: Seeker on
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

From: ozgrid.com on
Not sure I understand you, but try adding, as the top line;

Cancel=True
'YOUR CODE



--
Regards
Dave Hawley
www.ozgrid.com
"Seeker" <Seeker(a)discussions.microsoft.com> wrote in message
news:70772120-8D41-47A4-A8F5-0F9EA1A0726D(a)microsoft.com...
> 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
>

 | 
Pages: 1
Prev: Check numeric char
Next: Public Variable problem