To open a hyperlink from Excel in Microsoft Edge using VBA, use the Shell command with the msedge.exe path and the URL as an argument. This method launches Edge directly from a VBA macro, bypassing the default browser setting if needed.
What You'll Need
- Microsoft Excel with VBA editor access (Developer tab enabled)
- Microsoft Edge installed on the system (default location assumed)
- Basic knowledge of inserting and running VBA macros
Step-by-Step
- Open your Excel workbook and press ALT + F11 to launch the VBA Editor.
- In the VBA Editor, go to Insert > Module to create a new module.
- Copy and paste the following VBA code into the module window:
Sub OpenHyperlinkInEdge() Dim url As String Dim edgePath As String ' Replace with the actual cell containing the URL or hardcode it url = ThisWorkbook.Sheets("Sheet1").Range("A1").Value ' Default Edge installation path for 64-bit Windows edgePath = """C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe""" ' Check if the URL is not empty If url <> "" Then ' Use Shell to launch Edge with the URL as argument Shell edgePath & " " & url, vbNormalFocus Else MsgBox "No URL found in the specified cell.", vbExclamation End If End Sub - Adjust the sheet name ("Sheet1") and cell reference ("A1") to match where your URL is stored.
- If Edge is installed in a non-default location, update the
edgePathvariable accordingly. Common alternatives include:"C:\Program Files\Microsoft\Edge\Application\msedge.exe"(for some enterprise installations)"%PROGRAMFILES(X86)%\Microsoft\Edge\Application\msedge.exe"(uses environment variable)
- Close the VBA Editor and return to Excel.
- To run the macro, press ALT + F8, select
OpenHyperlinkInEdge, and click Run. - Alternatively, assign the macro to a button: go to Developer > Insert > Button (Form Control), draw it on the sheet, and assign
OpenHyperlinkInEdgewhen prompted. - Clicking the button will now launch Microsoft Edge and navigate to the URL from the specified cell.
Common Mistakes
- Using
FollowHyperlinkwithout specifying Edge, which always uses the system default browser. - Forgetting to wrap the Edge path in triple quotes (
""") when it contains spaces, causing a "file not found" error. - Assuming Edge is installed at
C:\Program Files\Microsoft\Edge\Application\msedge.exeon all systems — the(x86)path is correct for most 64-bit Windows installations. - Not validating that the cell contains a valid URL (e.g., missing
http://orhttps://), which may cause Edge to treat it as a search query. - Using
vbHideinstead ofvbNormalFocusin the Shell command, which launches Edge but doesn’t bring it to the foreground.
Tips
- Use
ThisWorkbook.Pathto build dynamic paths if distributing the workbook across machines with consistent Edge installations. - Add error handling to avoid crashes if Edge is not installed:
If Dir(edgePath) = "" Then MsgBox "Microsoft Edge not found at the specified path.", vbCritical Exit Sub End If - To open multiple URLs in separate Edge tabs, modify the code to loop through a range and use
--new-tabas an argument:Shell edgePath & " --new-tab " & url, vbNormalFocus
- If you want to use the user’s default Edge installation regardless of path, consider using the
microsoft-edge:protocol withFollowHyperlink, though this still respects the default app settings. - Test the macro on a copy of your workbook first to avoid unintended behavior.
Troubleshooting
- Edge does not open:
- Verify the
edgePathis correct by checking ifmsedge.exeexists at that location via File Explorer. - Try using the environment variable version:
edgePath = """%PROGRAMFILES(X86)%\Microsoft\Edge\Application\msedge.exe""". - Ensure you are not running Excel as administrator unless Edge is also installed for all users — permission mismatches can block execution.
- Verify the
- Edge opens but doesn’t navigate to the URL:
- Check that the cell value includes
http://orhttps://. If not, prepend it in VBA:If Left(url, 4) <> "http" Then url = "https://" & url
- Trim whitespace:
url = Trim(url).
- Check that the cell value includes
- "File not found" error:
- This means the Shell command cannot locate
msedge.exe. Double-check the path and quotes. - Use
Debug.Print edgePathin the Immediate Window (CTRL + G in VBA Editor) to verify the constructed path.
- This means the Shell command cannot locate
- Macro is blocked:
- Go to File > Options > Trust Center > Trust Center Settings > Macro Settings and enable macros (with caution).
- Save the file as a macro-enabled workbook (
.xlsm).
Frequently Asked Questions
Can I use this method to open links in Chrome or Firefox instead?
Yes, replace the edgePath with the path to chrome.exe or firefox.exe. For Chrome, use "C:\Program Files\Google\Chrome\Application\chrome.exe" as a common default.
Will this override the user’s default browser setting?
Yes, this method explicitly launches Edge regardless of the system default browser. To respect the default, use FollowHyperlink alone.
Do I need to update the macro if Microsoft updates Edge?
Only if the installation path changes, which is rare. Edge updates in place, so the msedge.exe path typically remains valid.
Can I open a local HTML file in Edge using this method?
Yes, pass the file path as the URL (e.g., "C:\file.html"). Edge will render it locally if allowed by security settings.
Is it possible to open Edge in InPrivate mode from VBA?
Yes, add the -inprivate argument: Shell edgePath & " -inprivate " & url, vbNormalFocus.
Why does Edge open but show a search instead of going to the URL?
This happens when the string passed lacks a protocol (http://) and Edge interprets it as a search term. Always ensure URLs begin with http:// or https://.