VBA cannot find file in path

kesss

New Member
Joined
Feb 13, 2018
Messages
4

<tbody>
[TD="class: votecell"]

[/TD]
[TD="class: postcell"] Hi I am trying to copy a folder from and paste it into another folder which I have created on my desktop. The creation of the folder went succesfully but copying doesn't seem to work for some reason. It keep getting the error that the filename cannot be found although the pathname is correct. Thanks

[/TD]

</tbody>
Hi

I am trying to copy a folder from and paste it into another folder which I have created on my desktop. The creation of the folder went succesfully but copying doesn't seem to work for some reason. It keep getting the error that the filename cannot be found although the pathname is correct.
Can somebody help?


Sub UsingScriptingRunObjectLibrary()


Dim fso As Scripting.FileSystemObject
Dim NewFolderPath As String

NewFolderPath = "C:\Users\muhar\Desktop\fso"


Set fso = New Scripting.FileSystemObject

If Not fso.FolderExists(NewFolderPath) Then
fso.CreateFolder NewFolderPath
End If

fso.CopyFile Source:="C:\Users\muhar\Desktop\varia\Automation\VBA Script\Oefen_excel.xls", Destination:="C:\Users\muhar\Desktop\fso" & "\VBA"
Application.DisplayAlerts = True

End Sub
 
Last edited by a moderator:

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi Dave

I have named the file 'Oefen_excel.xls' (practice excel in Dutch ) to keep it simple. It is a normal excel document.
For some reason vba keeps saying that the document can not be found although the pathname is correct.
I have created a folder with the following path name: "C:\Users\muhar\Desktop\fso" and this doesn't create an issue but "C:\Users\muhar\Desktop\varia\Automation\VBA Script\Oefen_excel.xls" above does.
Now I am kind of stuck....
thanks
 
Upvote 0
Cross posted https://stackoverflow.com/questions/48764341/vba-cannot-find-file-in-path#

Cross-Posting
While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Hi Dave

I tried with the xlsx extension and now it works!!!
Many thanks for this as I have lost a couple of hours trying other things to solve this.
You are great!
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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