logo
search
VBA & Macro Problems

How to Open Multiple Local File Hyperlinks in Excel Using VBA

Aamir Naveed AkramAamir Naveed Akram Oct 19, 2026 868 views

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.

How to Open Multiple Local File Hyperlinks in Excel with VBA
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.
Before you start

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.

Solution 1Recommended

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

1
Open the VBA Editor

Press the Alt + F11 keys on your keyboard simultaneously to open the Microsoft Visual Basic for Applications window.

2
Insert a New Module

In the top menu bar of the VBA window, click on 'Insert' and select 'Module' to create a new blank script window.

3
Paste the Macro Code

Copy the provided VBA code and paste it directly into the newly created module window.

4
Run the Macro

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.

Use a VBA Macro to Open Multiple Hyperlinks
Enable Macros: If your macro does not execute, check your Excel Trust Center settings to ensure that macros are enabled for your current session.
Seamless VBA Integration

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. 1. Open your workbook in WPS: Launch WPS Spreadsheet and open the Excel file containing your hyperlinks.
  2. 2. Access the VBA Editor: Navigate to the 'Developer' tab on the top ribbon and click 'VBA Editor', or simply press Alt + F11.
  3. 3. Insert and Run the Code: Insert a new module, paste the OpenHyperLinks macro code, run the macro, and select your target cell range.
Fully compatible with Microsoft Excel macro formats (.xlsm)Built-in VBA editor for writing, editing, and running scriptsFree and lightweight spreadsheet alternativeSupports local file hyperlinks and mapped drive URLs seamlessly
microsoft office alternative - wps office

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.