View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Simon Lloyd[_630_] Simon Lloyd[_630_] is offline
external usenet poster
 
Posts: 1
Default Macro for saving file on Auto Date


This makes a dated back up read only copy of a file at the end of each
month if it is opened at the end of the month taking in to account not
being used at weekends please feel free to modify this code to suit
your needs.

Simon

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim lDat_Today As Date
Dim lDat_Tomorrow As Date
Dim sStr As String
Dim myattr

With ThisWorkbook
If ActiveWorkbook.ReadOnly Then Exit Sub
lDat_Today = Date
If Format(Date, "ddd") = "Fri" Then
lDat_Tomorrow = Date + 3
Else
lDat_Tomorrow = Date + 1
End If

If Not Month(lDat_Today) = Month(lDat_Tomorrow) Then
sStr = .Path & "\" & _
Left(.Name, InStr(1, _
LCase(.Name), _
".xls") - 1) & _
" - " & Format(Now, "yyyymmdd") & ".xls"
On Error Resume Next
SaveCopyAs sStr
On Error GoTo 0
SetAttr sStr, vbReadOnly
End If
End With
End Sub


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=387166