Hi All,
I have the below code which imports a file to an access DB then adds the date to the file and moves the imported file to an archive folder.
I would like to add additional code that recognises if the file being moved already exists with the same date and to save a version 2. so essentially add a number to the end of the file name & date when moving if a duplicate. could someone suggest a code that does this? thanks!
I have the below code which imports a file to an access DB then adds the date to the file and moves the imported file to an archive folder.
I would like to add additional code that recognises if the file being moved already exists with the same date and to save a version 2. so essentially add a number to the end of the file name & date when moving if a duplicate. could someone suggest a code that does this? thanks!
VBA Code:
Function Import()
On Error GoTo ImportTaskDataFiles_Err
Dim objFS As Object, objFolder As Object
Dim objFiles As Object, objF1 As Object
Dim strFolderPath As String
strFolderPath = "\filelocation\CSV\"
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderPath)
Set objFiles = objFolder.files
'Import Txt Files
For Each objF1 In objFiles
If Right(objF1.Name, 3) = "txt" Then
'Add todays date and move file to Archive
Name strFolderPath & objF1.Name As "\\filelocation\Archive\" & Format(Now, "YYYY-MM-DD ") & objF1.Name
'can the additional code recognises this file already exists with that date and add version control to it?
End If
Next
Set objF1 = Nothing
Set objFiles = Nothing
Set objFolder = Nothing
Set objFS = Nothing
MsgBox ("Done")