+ Reply to Thread
Results 1 to 3 of 3

"Permission denied" error when trying to copy same file to multiple folders in a loop

  1. #1
    Registered User
    Join Date
    09-19-2017
    Location
    Bangalore
    MS-Off Ver
    windows7
    Posts
    2

    "Permission denied" error when trying to copy same file to multiple folders in a loop

    Hello All,

    I am trying to copy a file "x" to multiple folders based on a condition using FSO.copyfile as below
    1 For k = 1 To Lastrow
    2 movepath1 = filepath0 & "\" & Cells(k, 1).Value
    3 If InStr(Cells(k, 4).Value, "Human") > 0 Then
    4 Set FSO1 = CreateObject("Scripting.FileSystemObject")
    5 movepath2 = folderpath2 & "\Human\"
    6 FSO1.copyfile Source:=movepath1, Destination:=movepath2
    7 Set FSO1 = Nothing
    8 End If
    9 If InStr(Cells(k, 4).Value, "Field_staff") > 0 Then
    10 Set FSO1 = CreateObject("Scripting.FileSystemObject")
    11 movepath2 = folderpath2 & "\Fieldstaff"
    12 FSO1.copyfile Source:=movepath1, Destination:=movepath2
    13 Set FSO1 = Nothing
    14 End If
    15 Next k

    However, I am seeing "Permission denied" error at line number 12 incase same file is referred for copying.

    Please help me with some leads.

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: "Permission denied" error when trying to copy same file to multiple folders in a loop

    Please reply with the whole of your code (incl Sub and End Sub) for your procedure and enclose your code in code tags by clicking on # icon above and then pasting your code between the code tags
    [CODE ]Please Login or Register to view this content.[/CODE]
    Using code tags makes code easier to read and complies with Forum rules
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Registered User
    Join Date
    09-19-2017
    Location
    Bangalore
    MS-Off Ver
    windows7
    Posts
    2

    Re: "Permission denied" error when trying to copy same file to multiple folders in a loop

    hello Kev

    thanks for the reply and sorry for delay in my response.

    Please find the text file attached for the full code.

    Thanks
    Santhosh S L
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 1
    Last Post: 06-11-2015, 10:58 PM
  2. Replies: 0
    Last Post: 07-24-2014, 08:59 PM
  3. SendKeys "{ENTER}" in Macro...............Permission denied
    By BHD in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-30-2013, 06:26 PM
  4. Combobox using .additem "Permission Denied"
    By Schwizer in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-14-2007, 05:48 AM
  5. Permission denied in CreateObject(Excel.Application")
    By Leo in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2005, 01:10 PM
  6. Movefile "Permission Denied"
    By Gordon Gecko in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-09-2005, 04:05 PM
  7. Run-Time error "70" Permission Denied
    By Audrey in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 02-04-2005, 06:07 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1