Consulting

Results 1 to 4 of 4

Thread: Solved: Copy files runtime error 70 when trying to copy

  1. #1
    VBAX Regular
    Joined
    Oct 2007
    Posts
    97
    Location

    Solved: Copy files runtime error 70 when trying to copy

    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.
    [vba]ToPath = tempPath & "Documents and Settings" & "\" & tempUser & "\" & "Desktop" & "\" & FolderName[/vba]
    Everything goes fine up until the copy command where I have a runtime error 70, permission denied.
    [vba]Set FSO = CreateObject("scripting.filesystemobject")
    FSO.CopyFile Source:=FromPath & FileName, Destination:=ToPath[/vba]

    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?

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,359
    Location
    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).

  3. #3
    VBAX Regular
    Joined
    Oct 2007
    Posts
    97
    Location
    GTO, You are totally right. I added a path separator and it worked.
    [vba]
    ToPath = tempPath & "Documents and Settings" & "\" & tempUser & "\" & "Desktop" & "\" & FolderName & "\"
    [/vba]

    Thanks.

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,359
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •