# Move files to new folder as per list in excel



## atuljadhavnetafim (Jan 4, 2023)

Dear Expert

I have 2000+ PDF files in one folder "Current Location" now I want to move this in 3 folders which mentioned in "Desired Location".
i need to copy pdf files to desired location, the original should be in current location as it is.

can any one provide macro for that


File NameCurrent LocationDesired LocationBNCPK8159E_Q4_2020-21.pdfC:\Users\nishitp\Desktop\TDS Certificate AllC:\Users\nishitp\Desktop\TDS Certificate All\SBU SOUTH\ADUPP6015B_Q4_2020-21.pdfC:\Users\nishitp\Desktop\TDS Certificate AllC:\Users\nishitp\Desktop\TDS Certificate All\HEAD OFFICE\AWVPS9707M_Q4_2020-21.pdfC:\Users\nishitp\Desktop\TDS Certificate AllC:\Users\nishitp\Desktop\TDS Certificate All\HEAD OFFICE\ARCPS3364A_Q4_2020-21.pdfC:\Users\nishitp\Desktop\TDS Certificate AllC:\Users\nishitp\Desktop\TDS Certificate All\Chennai-Factory\ABGPD3118D_Q4_2020-21.pdfC:\Users\nishitp\Desktop\TDS Certificate AllC:\Users\nishitp\Desktop\TDS Certificate All\HEAD OFFICE\AAGFH7457J_Q4_2020-21.pdfC:\Users\nishitp\Desktop\TDS Certificate AllC:\Users\nishitp\Desktop\TDS Certificate All\HEAD OFFICE\ADWPV3973C_Q4_2020-21.pdfC:\Users\nishitp\Desktop\TDS Certificate AllC:\Users\nishitp\Desktop\TDS Certificate All\HEAD OFFICE\ALWPM6372J_Q4_2020-21.pdfC:\Users\nishitp\Desktop\TDS Certificate AllC:\Users\nishitp\Desktop\TDS Certificate All\SBU SOUTH\

Thanks in advance.


----------



## shinigamilight (Jan 4, 2023)

Enable microsoft scripting runtime in references.
*Code is untested*


```
Sub bye()
        
        Dim FSO As New FileSystemObject
        Dim des, sour As String
        Dim k As Integer
        Dim lr As Long
        lr = Range("A1").End(xlDown).Row
        
        For k = 2 To lr
                sour = Range("B" & k) & "\" & Range("A" & k)
                des = Range("C" & k)
                FSO.CopyFile sour, des
       Next k
       
        
        
End Sub
```


----------



## atuljadhavnetafim (Jan 5, 2023)

Hi,

below error show


----------



## atuljadhavnetafim (Jan 5, 2023)

another error


----------



## shinigamilight (Jan 6, 2023)

atuljadhavnetafim said:


> another error
> 
> View attachment 82189











						How do I use FileSystemObject in VBA?
					

Is there something that I need to reference? How do I use this:  Dim fso As New FileSystemObject Dim fld As Folder Dim ts As TextStream I am getting an error because it does not recognize these ob...




					stackoverflow.com


----------



## atuljadhavnetafim (Jan 7, 2023)

Already make changes in reference but still getting permission  error


----------



## shinigamilight (Jan 7, 2023)

atuljadhavnetafim said:


> Hi,
> 
> below error show
> 
> View attachment 82183


In column A there's no extension for the filename. If it still doesn't work then there's some permission conflict. Are you the admin of the PC?
Try this code now.



```
Sub bye()
        
        Dim FSO As object
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Dim des, sour As String
        Dim k As Integer
        Dim lr As Long
        lr = Range("A1").End(xlDown).Row
        
        For k = 2 To lr
                sour = Range("B" & k) & "\" & Range("A" & k)
                des = Range("C" & k) & "\"
                FSO.CopyFile sour, des
       Next k
       
        
        
End Sub
```


----------



## atuljadhavnetafim (Monday at 11:32 PM)

Yes, thanks, it's working,
i update file extension and use new code and it's working fine

Thanks a lot, it's save lot's of time.


----------

