W
wayliff
I have a routine that saves files to the network and I'm trying to fin
a way to have the macro delete the oldest file if it reaches seven.
Function GetName(Dia As Date) As String
Dim AuxStr As String
AuxStr = Format(Dia, "dd-mmm-yyyy")
GetName = "TC Report - " & AuxStr & ".xls"
End Function
********************
Route = "C:\Data"
Dim Name As String
Dim I As Integer
If Right(Route, 1) <> "\" Then Route = Route & "\"
Name = GetName(Now())
If Dir(Route & Name) <> "" Then
I = 1
Name = Left(Name, Len(Name) - 4)
While Dir(Route & Name & " Version (0" & I & ")" & ".xls") <> ""
I = I + 1
Wend
Name = Name & " Version (0" & I & ")" & ".xls"
End If
ActiveWorkbook.SaveAs Filename:=Route & Name, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False, AccessMode:
_
xlShared
ActiveWindow.Close
This is how the macro currently works.
What I want it to do is delete the oldest file and save the ne
one...by looking at the same name and date or something to the effect
There are other files that I dont want it to even consider.
Can this be done?
Any kind of help or guidance appreciated
a way to have the macro delete the oldest file if it reaches seven.
Function GetName(Dia As Date) As String
Dim AuxStr As String
AuxStr = Format(Dia, "dd-mmm-yyyy")
GetName = "TC Report - " & AuxStr & ".xls"
End Function
********************
Route = "C:\Data"
Dim Name As String
Dim I As Integer
If Right(Route, 1) <> "\" Then Route = Route & "\"
Name = GetName(Now())
If Dir(Route & Name) <> "" Then
I = 1
Name = Left(Name, Len(Name) - 4)
While Dir(Route & Name & " Version (0" & I & ")" & ".xls") <> ""
I = I + 1
Wend
Name = Name & " Version (0" & I & ")" & ".xls"
End If
ActiveWorkbook.SaveAs Filename:=Route & Name, _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False, AccessMode:
_
xlShared
ActiveWindow.Close
This is how the macro currently works.
What I want it to do is delete the oldest file and save the ne
one...by looking at the same name and date or something to the effect
There are other files that I dont want it to even consider.
Can this be done?
Any kind of help or guidance appreciated