View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Tim Zych Tim Zych is offline
external usenet poster
 
Posts: 389
Default Backup Copy of Source File

Here's a couple of reusable functions which are a variation of Bernie's
excellent approach.

Sub tester()
MsgBox GetNextIncrementedFullFilename("D:\Test", ".xls")
End Sub

Function GetNextIncrementedFullFilename(RootFilename As String, Optional
ByVal FileExt As String = ".xls") As String
Dim szFullFilename As String, i As Long
szFullFilename = RootFilename & FileExt
Do
If FileExists(szFullFilename) Then
' Found file, so increment it by one
i = i + 1
szFullFilename = RootFilename & "_" & Format(CStr(i), "00") &
FileExt
Else
' No file with this name.
Exit Do
End If
Loop
GetNextIncrementedFullFilename = szFullFilename
End Function

Public Function FileExists(ByVal strFullFileName As String) As Boolean
On Error GoTo ErrHandler
If Dir(strFullFileName) < "" And Len(strFullFileName) 0 Then
FileExists = True
Else
FileExists = False
End If
Exit Function
ErrHandler:
FileExists = False
End Function


--
Tim Zych
http://www.higherdata.com
Workbook Compare - Excel data comparison
Free & Pro versions


"Bob Zimski" wrote in message
...
I would like to make a make a backup copy and dump it into one directory
deeper called 'Archive' before manipulating the file in the current
directory. If the filename already exists in the Archive directory, then I
would want to add a '-01' or '-02' etc.. to the next revision level. I
know
about the FileCopy command, but have no idea how to determine if the file
already exists inthe archive directory and therefore add the next
available
revision number.

Thanks