LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Routine that saves a file. If more than 7 in directory, deletes the oldest.


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

--
waylif
-----------------------------------------------------------------------
wayliff's Profile: http://www.excelforum.com/member.php...fo&userid=2986
View this thread: http://www.excelforum.com/showthread.php?threadid=49613

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
shared file adds or deletes rows woodman Excel Discussion (Misc queries) 0 May 31st 07 04:46 PM
VLOOKUP - Saves entire directory structure Armatidge Excel Worksheet Functions 0 February 20th 07 01:53 AM
Randon file saves Gary''s Student Excel Discussion (Misc queries) 1 October 24th 06 09:09 PM
How to make a routine that will automatically print a word file after it has been changed via an ole link to an excel file? Starriol Excel Programming 0 November 3rd 05 11:59 AM
Name x as y Deletes file Brad Excel Programming 1 October 25th 05 09:18 PM


All times are GMT +1. The time now is 10:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"