Copy excel to new folder path - break

godzilla185

New Member
Joined
Sep 27, 2021
Messages
18
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
I think you are missing the slash after the last folder, i.e.
VBA Code:
'Change to match the source folder path
sSFolder = "C:\Users\name\Downloads"

'Change to match the destination folder path
sDFolder = "C:\Users\name\Documents"
should be:
VBA Code:
'Change to match the source folder path
sSFolder = "C:\Users\name\Downloads\"

'Change to match the destination folder path
sDFolder = "C:\Users\name\Documents\"

Otherwise there is no slash after the last folder and the file name here:
VBA Code:
sSFolder & sFile
 
Upvote 0
Solution
Thanks Joe. I was missing a darn slash which was causing everything to break! hahaha
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,223,657
Messages
6,173,629
Members
452,525
Latest member
DPOLKADOT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top