View Full Version : Close macro not saving my changes


dfuas
02-19-2006, 11:31 AM
Hi

I just wrote my first macro in Excel, but the problem is not saving any changes I make when I click the close button on the right top corner.
Can anyone help, please?

Sub Auto_Close()

Dim OrigName As String
OrigName = ActiveWorkbook.FullName
ActiveWorkbook.Save

End sub

thanks
dfuas

HaHoBe
02-20-2006, 01:23 AM
Hi, dfuas,

and where did you place the macro? It should be in a normal code module. Anyhow - as no changes are being made to the name of the workbook the following code should do the job:

Sub Auto_Close()

ThisWorkbook.Save 'will only save workbook with code

End Sub
And I would prefer to use the Workbook_BeforeClose(Cancel As Boolean)-event to save the workbook (code goes into ThisWorkbook):

Option Explicit

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Save
End Sub
If code doesnīt work did you set the security level for macros to medium and starting with Excel2002 the checkbox near to trust VBA-Project (donīt know the proper expression in english - sorry)?

Ciao,
Holger