Closing and saving a spread sheet

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
 
R

Ron de Bruin

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
 
G

GB

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top