VBA open PDF from range with wildcard

AnnieLox

New Member
Joined
Sep 18, 2017
Messages
22
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]

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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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