VBA Code to Move 5000 PDF's into subfolders

bergman99

New Member
Joined
May 5, 2014
Messages
8
Hi folks!

I've got a folder that has 5000+ pdf's in it. I've got a spreadsheet as shown below. I'd like to run a sub that copies the pdf's in the original folder and pastes them into the new folder..

Is anyone able to help?


PDF NamePDF TypeCurrent FolderCopy to New Folder
pdf001Type 1C:\MyPDFFolder\C:\MyPDFFolder\Type1\
pdf002Type 2C:\MyPDFFolder\C:\MyPDFFolder\Type2\
pdf003Type 3C:\MyPDFFolder\C:\MyPDFFolder\Type3\
pdf004Type 1C:\MyPDFFolder\C:\MyPDFFolder\Type4\

<tbody>
</tbody>


Thanks!!
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
But precisely where is the code supposed to get the Type data from? Do the destination folders already exist? Also, how are these PDFs being created? If they're being created from the workbook using the macro, why not create them in the destination folders in the first place? Finally, are the files being moved or copied?
 
Upvote 0
The spreadsheet is complete, the PDF type, current folder and new folder are already populated. The PDF's already exist in the current folder, all 5000 of them. I would like the code to copy the PDF from the "current folder" location into the folder specified in the "Copy to New Folder" column..

Does that make sense?
 
Upvote 0
Try this:
Code:
Public Sub Copy_Files()

    Dim lr As Long, r As Long
    
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    For r = 2 To lr
        FileCopy Cells(r, 3).Value & Cells(r, 1).Value & ".pdf", Cells(r, 4).Value & Cells(r, 1).Value & ".pdf"
    Next
    
    MsgBox "Done"
    
End Sub
 
Upvote 0
Try:
Code:
Sub CopyPDFs()
Dim i As Long, StrNm As String
Const StrFldSrc As String = "C:\MyPDFFolder\"
With ActiveSheet.UsedRange
  For i = 2 To .Cells.SpecialCells(xlCellTypeLastCell).Row
    Application.StatusBar = "Copying File " & i
    StrNm = .Cells(i, 1).Value & ".pdf"
    FileCopy StrFldSrc & StrNm, .Cells(i, 4).Text & StrNm
  Next
End With
Application.StatusBar = False
MsgBox "Done", vbExclamation
End Sub
This one gives a progress report as well.
 
Upvote 0

Forum statistics

Threads
1,215,391
Messages
6,124,679
Members
449,179
Latest member
jacobsscoots

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top