2 Attachment(s)
Copy/Paste files into new folders based on condition
Hi
New to Excel VBA and was hoping someone could help.
I am trying to create a macro wherein 20 folders are created (names of folders are from the range of cells e.g. B2:B21). This seems to work OK.
I am then trying to copy 5 (different) pdf files (which are chosen according to a criteria ie. score of <=50%) into each of the 20 folders. This bit is not working properly and I think it's because the cell.Value (which contains the pdf location) is just a file path so the actual physical pdf is not being copied? Please see code below.
Can anyone help me with copying the relevant pdf files across into each of the 20 folders. Or alternative could be that all 5x20=100 pdfs are copied into 1 folder but sorted in some way so I know which pdfs belong to which candidate?
I've attached my files also. Would really appreciate any help here as I'm not sure I am doing this correctly.
Also I've commented out the shell call which I know you can use to print ... but I need copy/paste into new folders instead.
Code:
'CREATE INDIVIDUAL FOLDERS
On Error Resume Next
For Each cell In rng2
FldrName = cell
MkDir "C:\Users\test\Documents\Files" & FldrName
Next cell
'COPY PDF FILES IN COLUMN D TO CREATED FOLDERS
For Each cell In rng1
If cell.Offset(0, 3) <= 0.5 And count <= 5 Then
If Not dnary.Exists(cell.Value) Then
dnary.Add cell.Value, 1
FileCopy cell.Value, "C:\Users\test\Documents\Files" & FldrName
'Call apiShellExecute(Application.hwnd, "print", cell.Value, vbNullString, vbNullString, 0)count = count + 1
End If
End If
Next cell