Put this code in your "Thisworkbook" module.
It tests to see if tomorrow is the same month as today.
If it is this just performs a save.
If it isn't, then a dated backup is also created.
'' - - - - Code begins
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim lDat_Today As Date
Dim lDat_Tomorrow As Date
Dim lStr_TargetFile As String
lDat_Today = Date
lDat_Tomorrow = Date + 1
With ThisWorkbook
If Month(lDat_Today) = Month(lDat_Tomorrow) Then
'' Do nothing, we're still in the same month
Else
'' Tomorrow is a new month so make a backup today
.SaveCopyAs ThisWorkbook.Path & "\" & _
Left(ThisWorkbook.Name, InStr(1, LCase(ThisWorkbook.Name),
".xls") - 1) & _
" - " & Format(Now, "yyyymmdd") & ".xls"
End If
'' Save the original
.Save
End With
End Sub
'' - - - - Code Ends
--
Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"
"Simon Lloyd " wrote in message
...
Hi all,
Can anyone tell me how to create a monthly backup of my file when
autoclose is initiated? the file will most probably be used most days
of the week so after a month has passed when it is next closed i would
like a back up copy to made to P:\public\training\development, but
every month it makes a back up copy it needs to have a different date
say "trainingBkUp7.7.04" and next month it would be
"trainingBkUp7.8.04" etc.
Can anyone help?
Simon.
P.S the Auto_close just updates the file and saves it to its current
location and its current filename (Workbook.Save)
---
Message posted from http://www.ExcelForum.com/