godzilla185
New Member
- Joined
- Sep 27, 2021
- Messages
- 18
- Office Version
- 365
- Platform
- Windows
Hi wonderful excel masters of the internet!
I am trying to copy an excel file from one folder to another. This excel file always has the same name, but the date changes to current date.
I have the below code but every time I try and execute it tells me "Specified File Not Found".
I have used this code for other excel copy pastes before--the only difference with the other excels is that the file names were 'date first then text', whereas this is 'text then date'
Sub TestFileMove()
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder As String
'This is Your File Name which you want to Copy
sFile = "test_" & Format(Now, "yyyymmdd") & ".csv"
'Change to match the source folder path
sSFolder = "C:\Users\name\Downloads"
'Change to match the destination folder path
sDFolder = "C:\Users\name\Documents"
'Create Object
Set FSO = CreateObject("Scripting.FileSystemObject")
'Checking If File Is Located in the Source Folder
If Not FSO.FileExists(sSFolder & sFile) Then
MsgBox "Specified File Not Found", vbInformation, "Not Found"
'Copying If the Same File is Not Located in the Destination Folder
ElseIf Not FSO.FileExists(sDFolder & sFile) Then
FSO.CopyFile (sSFolder & sFile), sDFolder, True
MsgBox "Specified File Copied Successfully", vbInformation, "Done!"
Else
MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists"
End If
End Sub
I am trying to copy an excel file from one folder to another. This excel file always has the same name, but the date changes to current date.
I have the below code but every time I try and execute it tells me "Specified File Not Found".
I have used this code for other excel copy pastes before--the only difference with the other excels is that the file names were 'date first then text', whereas this is 'text then date'
Sub TestFileMove()
Dim FSO
Dim sFile As String
Dim sSFolder As String
Dim sDFolder As String
'This is Your File Name which you want to Copy
sFile = "test_" & Format(Now, "yyyymmdd") & ".csv"
'Change to match the source folder path
sSFolder = "C:\Users\name\Downloads"
'Change to match the destination folder path
sDFolder = "C:\Users\name\Documents"
'Create Object
Set FSO = CreateObject("Scripting.FileSystemObject")
'Checking If File Is Located in the Source Folder
If Not FSO.FileExists(sSFolder & sFile) Then
MsgBox "Specified File Not Found", vbInformation, "Not Found"
'Copying If the Same File is Not Located in the Destination Folder
ElseIf Not FSO.FileExists(sDFolder & sFile) Then
FSO.CopyFile (sSFolder & sFile), sDFolder, True
MsgBox "Specified File Copied Successfully", vbInformation, "Done!"
Else
MsgBox "Specified File Already Exists In The Destination Folder", vbExclamation, "File Already Exists"
End If
End Sub