Macro To Open .pdf file From Partial Filename

troywa

New Member
Joined
Jul 20, 2015
Messages
1
Trying to make a macro to open a .pdf file whose file name contains the selected "Item number" in a spreadsheet. It will open in Internet Explorer. I'm getting close, I can open a file if its entire file name is the item number:

Sub OpenPDF()


Application.DisplayAlerts = False
X = ActiveCell.Row
Cells(X, 1).Select
Item = Cells(X, 1).Value
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "\\File Folder\" & Item & ".pdf"

End Sub

but can't figure out how to include a wildcard for file names begin with the item number. I have tried several variants on the following with no luck:

Sub OpenPDF()


Application.DisplayAlerts = False
X = ActiveCell.Row
Cells(X, 1).Select
Item = Cells(X, 1).Value
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
IE.Navigate "\\File Folder\" & Item & * & ".pdf"

End Sub
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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