PDA

View Full Version : [SOLVED] Copy .pdf files from one location to a new folder based on a list of cell



GregWalter
12-04-2019, 09:36 AM
1st time poster and VBA newby. I'm looking for a macro to copy a set .pdf files to a new folder(to be created if not already made) corresponding to the person they are assigned to. I have a snip below to show the columns(D&K). Right now we have all the IWP files matched with a similarly named .pdf in a folder(X:\03_IWP\IWP pdf) and I am looking to copy them into a new folder based on the Superintendent in another location(X:\03_IWP\Superintendent).

Thank you for any help you can give!

Currently using excel 2016

25529

mancubus
12-05-2019, 02:21 AM
welcome to the forum.

is it that you want to copy (for D2) X:\03_IWP\IWP pdf\IWAA05C11000-000.pdf to X:\03_IWP\Superintendent\Jorge Rodriguez\IWAA05C11000-000.pdf

mancubus
12-05-2019, 02:42 AM
if my guess is correct, you can try this:


Sub vbax_66359_copy_files()

Dim sPath As String, dPath As String
Dim i As Long


With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With

sPath = "X:\03_IWP\IWP pdf\"
dPath = "X:\03_IWP\Superintendent\"


With CreateObject("Scripting.FileSystemObject")
For i = 2 To Range("D" & Rows.Count).End(xlUp).Row
If Not .FolderExists(dPath & Range("K" & i).Value) Then .CreateFolder (dPath & Range("K" & i).Value)
.CopyFile sPath & Range("D" & i).Value & ".pdf", dPath & Range("K" & i).Value & "\"
Next i
End With

End Sub

GregWalter
12-05-2019, 06:20 AM
Thanks for the help! That was what I was looking for!

mancubus
12-09-2019, 12:50 AM
you are welcome.

pls mark the thread as "solved" (see #4 in my forum signature) for future references to this thread.