Why am I keeping have this error in VBA

eliW

Well-known Member
Joined
Mar 2, 2002
Messages
1,940
Hi all,
I am trying to copy files from a folder and subfolders to another destination according to list in first column of a worksheet.
BTW, the list contains full path and file name like this:
HTML:
713It's My Party -Lesley Gore.mp3	F:\A04
714Sleep walk -Santo and Johnny.mp3	F:\A04
Exexcuting this macro gives me a constant error on the red line saying:
PHP:
Run Time Error 70
Permission Denied

Code:
Sub copyfiles()
[COLOR="#00FF00"]'copy files from folder and subfolders to another folders[/COLOR]

Dim m, x As Variant
Dim Copier
Dim FileName As String
Dim FileType As String
Dim FilePath As String

'On Error Resume Next
m = Range("A1").CurrentRegion.Count

Set Copier = CreateObject("Scripting.FileSystemObject")
For x = 1 To m
FileName = Cells(x, 1).Value
FilePath = Cells(x, 2).Value
[COLOR="#00FF00"]'Copier.copyfile "C:\Users\User\Desktop\rivka\" & FileName, [/COLOR]"C:\Users\User\Desktop\songs\"
[COLOR="#FF0000"]Copier.copyfile FilePath & "\" & FileName, "C:\Users\User\Desktop\jjj"[/COLOR]
[COLOR="#00FF00"]'Copier.copyfile FileName, "C:\Users\User\Desktop\jjj"[/COLOR]
Next
MsgBox ("done")
'
End Sub

Any help will be apreciated,
Eli
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I assume you can copy there manually.?
Code:
You will need a "\" after any path.? You do not have one in "C:\Users\User\Desktop\jjj" yet you put one in FilePath & "" & FileName ?

Last sentence in code tags as site removes the \ otherwise?
 
Last edited:
Upvote 0
I assume you can copy there manually.?
Code:
You will need a "\" after any path.? You do not have one in "C:\Users\User\Desktop\jjj" yet you put one in FilePath & "" & FileName ?

Last sentence in code tags as site removes the \ otherwise?

Hi welshgasman,
This indeed was the problem -simple slash.
Thank you very much,
Eli :)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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