Closing and saving a spread sheet

  • Thread starter Thread starter mkaufman
  • Start date Start date
M

mkaufman

I am trying to use a macro to save and close a Excel XP spreadsheet.
The problem is when i run the macro the macro works but I cant figure
out how to activiate the macro when I click on either the X box or use
the close command.
The macro below is what i am currently using:

Sub test2()
ActiveWorkbook.Close True
Close

End Sub
 
You can use this event if you always want to save the workbook
you must place it in the thisworkbook module

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
End Sub
 
You can trap the close and save events using the This Workbook module. For
example this event:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

End Sub


or

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

End Sub



Does this help?

Geoff
 
Back
Top