PDA

View Full Version : [SOLVED:] Copy files runtime error 70 when trying to copy



fadib
12-23-2011, 12:57 PM
Hey Guys,
I am using VBA to copy a file from one folder already on the desktop (From Path), to another folder (ToPath) I create through VBA on the desktop.

ToPath = tempPath & "Documents and Settings" & "\" & tempUser & "\" & "Desktop" & "\" & FolderName
Everything goes fine up until the copy command where I have a runtime error 70, permission denied.

Set FSO = CreateObject("scripting.filesystemobject")
FSO.CopyFile Source:=FromPath & FileName, Destination:=ToPath

I did some troubleshooting, and noticed that if I manually create the "ToPath" folder, the file gets copied without any error.

Am I forgetting something to declare?
Have anyone faced such error?

GTO
12-23-2011, 02:26 PM
How are you creating the folder on the desktop? As shown, if FolderName ends in a path seperator, Foldername must already exist. If no trailing path seperator is in FolderName, Foldername becomes the name of the copied file (which would be created on the desktop).

fadib
12-23-2011, 02:48 PM
GTO, You are totally right. I added a path separator :thumb and it worked.



ToPath = tempPath & "Documents and Settings" & "\" & tempUser & "\" & "Desktop" & "\" & FolderName & "\"


Thanks.

GTO
12-23-2011, 06:08 PM
Hi Fadib,

You are most welcome :-)

If solved, there is an option under Thread Tools (that will show only to you, the thread's initiator) to mark the thread "Solved". This saves "answerers" time in checking.

Mark