You can use the FollowHyperlink method in VBA to open a PDF file from a specific file path.
Here is one common way to use this method in practice:
This particular macro opens the pdf called basketball_data.pdf located in a specific folder on my computer.
By default, the PDF file will be opened using the default PDF reader on your own computer.
The following example shows how to use this syntax to read a text file in practice.
Example: How to Open a PDF Using VBA
Suppose we have a PDF file called basketball_data.pdf located at the following file path:
Suppose we would like to open this PDF using VBA.
We can create the following macro to do so:
When we run this macro, we may receive the following Microsoft Excel Security Notice that simply lets us know this location may be unsafe and asks if we’d like to proceed anyway:
Once we click Yes, the PDF will then be opened:
This particular PDF simply contains a dataset about basketball players on various teams.
Note: You can find the complete documentation for the FollowHyperlink method here.
The following tutorials explain how to perform other common tasks in VBA: