I am trying to edit a macro I have to open a list of PDFs.
I have been reading and trying to teach myself how to code for almost a year... but I just am slow..
the current code moves any file from folder A containing x variant to the correct folder. I would like to change the code to open all the files that i past into the range.
the PDF files i am opening will have additional text in the name, but if the file name contains what is in column A it will move it, despite additional text.
it currently has 450 rows is set up as such:
[TABLE="width: 806"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Name[/TD]
[TD]From Path[/TD]
[TD]To Path[/TD]
[/TR]
[TR]
[TD]23 FREIGHT 5B FREIGHT[/TD]
[TD]T:\All Vendors Invoices\ALL VENDORS\[/TD]
[TD]T:\All Vendors Invoices\23 FREIGHT 5B FREIGHT\[/TD]
[/TR]
</tbody>[/TABLE]
I will only be opening lists of PDF's or Excels from the same folder so I am prepared to adjust the range to this:
[TABLE="width: 376"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Name[/TD]
[TD]From Path[/TD]
[/TR]
[TR]
[TD]2614998[/TD]
[TD]T:\All Vendors Invoices\LINDEN BULK\[/TD]
[/TR]
</tbody>[/TABLE]
I have been reading and trying to teach myself how to code for almost a year... but I just am slow..
the current code moves any file from folder A containing x variant to the correct folder. I would like to change the code to open all the files that i past into the range.
the PDF files i am opening will have additional text in the name, but if the file name contains what is in column A it will move it, despite additional text.
it currently has 450 rows is set up as such:
[TABLE="width: 806"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]Name[/TD]
[TD]From Path[/TD]
[TD]To Path[/TD]
[/TR]
[TR]
[TD]23 FREIGHT 5B FREIGHT[/TD]
[TD]T:\All Vendors Invoices\ALL VENDORS\[/TD]
[TD]T:\All Vendors Invoices\23 FREIGHT 5B FREIGHT\[/TD]
[/TR]
</tbody>[/TABLE]
I will only be opening lists of PDF's or Excels from the same folder so I am prepared to adjust the range to this:
[TABLE="width: 376"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Name[/TD]
[TD]From Path[/TD]
[/TR]
[TR]
[TD]2614998[/TD]
[TD]T:\All Vendors Invoices\LINDEN BULK\[/TD]
[/TR]
</tbody>[/TABLE]
Code:
Sub MoveFiles()
Dim d As String, ext As Variant, x As Variant
Dim srcPath As String, destPath As String, srcFile As String
Dim FSO As Object
Dim LR As Long
Dim Rw As Long
Set FSO = CreateObject("scripting.filesystemobject")
With Sheets("Macro")
For Rw = 2 To .Range("A" & Rows.Count).End(xlUp).Row
srcPath = .Range("B" & Rw).Value
destPath = .Range("C" & Rw).Value
ext = Array("*.xls*", "*.pdf", "*.doc*", "*.msg*")
For Each x In ext
d = Dir(srcPath & x)
Do While d <> ""
If d Like "*" & .Range("A" & Rw).Value & "*" _
And Not d Like "* CK*" Then
srcFile = srcPath & d
On Error Resume Next
FSO.MoveFile srcPath & d, destPath & d
On Error GoTo 0
End If
d = Dir
Loop
Next x
Next Rw
End With
End Sub