Runtime Error 70: Permission Denied while copying folders RRS feed

  • Question

  • I have an excel VBA procedure to copy a selection of folders from one computer (Vista / Office 2007) to a laptop (Windows 7 / Office 2007) that has a user mapped as network drive Z on the Vista computer.  A user form selects whether a large number of folders or just a subset is copied.  When the smaller subset is selected the procedure works correctly.  When the larger set is selected I get:  The previous two sentences in Italics are no longer true so I have edited the question.  So I suspect that something that got transferred when I ran the smaller subset has caused the problem.  Now I get the following message when either box is checked.

    Runtime error 70:

    Permission Denied.

    I have checked the sharing and security on all the affected folders on both computers and have set sharing for everyone with full control or read/write as appropriate.  I still get the error, but only on the first section of the code, where  "cbxMyDocuments" is true.  The code where "cbxEbayFolders" is true runs without error.  The Help button on the error message did not seem to offer anything relevant!

    The code is below

    Private Sub BackupFolders_Click()
        If cbxMyDocuments = False And cbxEbayFolders = False Then
            MsgBox "No Folders were selected."
            Exit Sub
        End If
        Set objFileSys = CreateObject("Scripting.FileSystemObject")
        'If My Documents ticked, copy to laptop
        If cbxMyDocuments = True Then
            strFolderToCopy = "C:\Users\Charles\Documents"
            strFolderBup = "Z:\"
            objFileSys.CopyFolder strFolderToCopy, strFolderBup    'THIS IS THE LINE WHERE THE ERROR OCCURS
        End If

        'The folders data is already included in the My Documents data.
            'So if both boxes are ticked, then the next bit will not run.

        If cbxEbayFolders = True And cbxMyDocuments = False Then
            'Copy the main body of eBay data
            strFolderToCopy = "C:\Users\Charles\Documents\chas"
            strFolderBup = "Z:\Documents\"
            objFileSys.CopyFolder strFolderToCopy, strFolderBup   'THIS IS THE LINE WHERE THE ERROR OCCURS
            'Copy the Turbo Lister folder.
            strFolderToCopy = "C:\Users\Charles\Documents\Turbo Lister"
            strFolderBup = "Z:\Documents\"
            objFileSys.CopyFolder strFolderToCopy, strFolderBup
            'Copy the Turbo Lister Backup folder.
            strFolderToCopy = "C:\Users\Charles\Documents\Turbo Lister Backup"
            strFolderBup = "Z:\Documents\"
            objFileSys.CopyFolder strFolderToCopy, strFolderBup
        End If
        Set objFileSys = Nothing
        Unload BakupToLaptop
    End Sub

    The error does not occur in the final two Folder copying events ("'Copy the Turbo Lister folder." and "'Copy the Turbo Lister Backup folder. ") if I step over the error in the "'Copy the main body of eBay data" event, but those two folders are empty and had been included only for development of the procedure.

    Any suggestions will be gratefully received

    • Edited by AndyColRomsey Friday, March 8, 2013 2:46 PM correct description of problem
    Friday, March 8, 2013 12:00 PM

All replies

  • Ensure that you are not attempting to copy a temporary file that gets created with Excel and/or the project workbook itself. Instead of copying entire folders, test for the existance of the destination folder and if necessary create it and then you might need to be selective of the of files to copy by their file extension. 

    Regards, OssieMac

    Sunday, March 10, 2013 10:43 AM
  • OssieMac

      Thanks for your input.  I had considered windows and system files in my further attempts as diagnosis, but forgot about temporary files.  When I manually drag and drop the folders in Windows explorer, the copying goes without problem (though I do get asked about desktop.ini files etc), so clearly it is possible to do it.  Further trouble-shooting seems to indicate that the problem lies in the "special" folders (My documents, My Pictures etc), and I shall see if I can test the attributes of each folder in a loop, then test the attributes of each file in those folders.  However, since the final destination for this procedure will have to copy about 50Gb of data, which already takes hours to do manually, I suspect that individual testing may take days!  In the long run it may be simpler just to do it all through Windows Explorer.

    Best wishes


    Monday, March 11, 2013 10:48 AM
  • I eventually gave up trying to find an answer to this problem using VBA commands throughout, and instead learned about batch files.  Using the Shell command and a batch file with xcopy in the command line I have achieved the same end with considerably less code!

    Andy C

    Tuesday, April 30, 2013 2:59 PM