Phil Riley
New Member
- Joined
- Apr 8, 2002
- Messages
- 6
I am trying to get this piece of code to work:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
myans = MsgBox("Do you want to save the changes you made?", 67)
If myans = vbYes Then
Sheets(1).Range("A1") = ""
ActiveWorkbook.Save
ResetExcel
ActiveWorkbook.Close
ElseIf myans = vbNo Then
ResetExcel
ActiveWorkbook.Close
End If
Cancel = True
End Sub
..but when I run it, the ActiveWorkbook.Close command triggers the whole routine again! Can I put a line in just before which will stop this happening?
Private Sub Workbook_BeforeClose(Cancel As Boolean)
myans = MsgBox("Do you want to save the changes you made?", 67)
If myans = vbYes Then
Sheets(1).Range("A1") = ""
ActiveWorkbook.Save
ResetExcel
ActiveWorkbook.Close
ElseIf myans = vbNo Then
ResetExcel
ActiveWorkbook.Close
End If
Cancel = True
End Sub
..but when I run it, the ActiveWorkbook.Close command triggers the whole routine again! Can I put a line in just before which will stop this happening?