How to Open Multiple Local File Hyperlinks in Excel Using VBA
Question details
The user needs to open a batch of local file hyperlinks (like PDFs on a mapped drive) from a selected range in Excel using a VBA macro without manually clicking each link.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- Automating the process of opening multiple local file and web hyperlinks from a selected Excel spreadsheet range.
- Observed behavior
- Excel requires manual clicking for each hyperlink, requiring a VBA macro to automatically open file links in new windows and web links normally.
Ensure your Excel workbook is saved as an Excel Macro-Enabled Workbook (.xlsm) to retain your VBA code, and verify that the target local files or mapped network drives are accessible.
Use a VBA Macro to Open Multiple Hyperlinks
Implement a custom VBA script to iterate through a selected range, automatically opening both local file links and web hyperlinks.
To accomplish this, you can use a customized VBA macro that loops through a selected range of cells. The script dynamically checks the hyperlink type and opens file links in a new window while processing standard web links normally.
Here is the code you will need to use: Sub OpenHyperLinks() Dim xHyperlink As Hyperlink Dim WorkRng As Range On Error Resume Next xTitleId = "OpenHyperlinksInExcel" Set WorkRng = Application.Selection Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) For Each xHyperlink In WorkRng.Hyperlinks If xHyperlink.Type = xlHyperlinkTypeFile Then xHyperlink.Follow NewWindow:=True Else xHyperlink.Follow End If Next End Sub
Press the Alt + F11 keys on your keyboard simultaneously to open the Microsoft Visual Basic for Applications window.
In the top menu bar of the VBA window, click on 'Insert' and select 'Module' to create a new blank script window.
Copy the provided VBA code and paste it directly into the newly created module window.
Press F5 or click the 'Run' button (the green triangle) in the toolbar. A dialog box will appear asking you to select the range of cells containing your hyperlinks. Make your selection and click OK.

Run VBA Macros to Open Hyperlinks in WPS Office
WPS Office provides excellent support for Excel VBA macros. You can run the exact same VBA script to open multiple hyperlinks in WPS Spreadsheet without changing your workflow.
- 1. Open your workbook in WPS: Launch WPS Spreadsheet and open the Excel file containing your hyperlinks.
- 2. Access the VBA Editor: Navigate to the 'Developer' tab on the top ribbon and click 'VBA Editor', or simply press Alt + F11.
- 3. Insert and Run the Code: Insert a new module, paste the OpenHyperLinks macro code, run the macro, and select your target cell range.

Frequently Asked Questions
Why are my local file hyperlinks not opening with the macro?
This usually happens if the file path is incorrect, the destination file has been moved, or you lack permission to access the mapped network drive. Verify that the hyperlink works manually before running the macro.
How do I save my file after adding this VBA macro?
You must save your spreadsheet as an Excel Macro-Enabled Workbook (*.xlsm). If you save it as a standard .xlsx file, Excel will discard your VBA code upon closing.
Can this macro open PDF files directly?
Yes, if the local file hyperlink points to a PDF document, the macro will trigger your system's default PDF viewer (like Adobe Acrobat, WPS Office, or your browser) to open the file in a new application window.




