Dears,
I have a macro that is opening all txt file from a specified folder, do some actions in Excel and then move them to a destination folder.
I'd like to avoid possible errors in case the file already exists in the destination folder.
To move the files I use File.Move which I guess has no feature to handle this situation.
I though to rename the file in the loop adding the timestamp at the end, but my VBA knowledge is still quite limited.
Do you have some advices for me?
Thanks,
D
I have a macro that is opening all txt file from a specified folder, do some actions in Excel and then move them to a destination folder.
I'd like to avoid possible errors in case the file already exists in the destination folder.
To move the files I use File.Move which I guess has no feature to handle this situation.
I though to rename the file in the loop adding the timestamp at the end, but my VBA knowledge is still quite limited.
VBA Code:
Sub Test()
Dim orig_path As String, path As String, MyFile As Variant, a As Variant, count As Integer
orig_path = "C:\AAA"
dest_path = "C:\BBB"
With CreateObject("scripting.filesystemobject")
For Each MyFile In .GetFolder(orig_path).Files
If .GetExtensionName(MyFile) = "txt" Then
'long code here to do open txt file, import in excel, etc.
MyFile.Move (dest_path & "\" & MyFile.Name)
End If
Next
End With
End Sub
Do you have some advices for me?
Thanks,
D