VBA & Macro Problems

Insert a Website Hyperlink in Excel Using VBA

Aamir Naveed AkramAamir Naveed Akram Nov 18, 2026 869 views

Question details

Retrieve website data and a unique URL, then insert the URL as a clickable hyperlink in an Excel worksheet using VBA.

Insert a Website Hyperlink in Excel Using VBA
Product
Microsoft Excel
Device & OS
not provided
Scenario
A user wants to bring website data into a worksheet and create a link to the associated page.
Observed behavior
The worksheet should contain a clickable hyperlink pointing to the retrieved URL.
Before you start

Identify the website field that contains the unique URL and check whether the site offers an API or data source that Power Query can access. For protected sites, use a supported authentication method and confirm that automated access complies with the site’s terms.

Solution 1Recommended

Retrieve the URL and add a hyperlink with Excel VBA

Use this method when you can obtain the website’s URL through an API, Power Query, or another supported source.

1
Retrieve the website data

In Excel, select Data > Get Data > From Other Sources > From Web, enter an accessible website or API URL, and use the Power Query editor to select the data containing the unique URL. Authenticate if prompted, then load the result to a worksheet.

2
Place the URL in A1

Copy the retrieved URL as plain text into cell A1 of the worksheet where you want the hyperlink. This example creates the link in A2; adjust the cell references in the macro if needed.

3
Add the VBA macro

Open the Visual Basic Editor from Developer > Visual Basic, choose Insert > Module, and paste this code: Sub AddWebsiteLink() Dim url As String url = ActiveSheet.Range("A1").Value If Len(url) > 0 Then ActiveSheet.Hyperlinks.Add Anchor:=ActiveSheet.Range("A2"), Address:=url, TextToDisplay:="Open website" End If End Sub

4
Run and save the macro

Activate the worksheet containing the URL, then select Developer > Macros, choose AddWebsiteLink, and click Run. Check the link in A2, and use File > Save As to save the workbook as an Excel Macro-Enabled Workbook (.xlsm).

Retrieve the URL and add a hyperlink with Excel VBA
Some websites need a different retrieval method: Power Query may not expose data rendered by a website’s scripts or support its login flow. Use an official API or supported browser automation when necessary; Internet Explorer automation is obsolete. Do not store passwords directly in workbook code.
Free Microsoft Office alternative

Work with website hyperlinks in WPS Spreadsheets

WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility, making it easy to move everyday spreadsheet work between suites. You can add a retrieved URL as a worksheet hyperlink in WPS Spreadsheets; Excel-specific VBA automation may require Microsoft Excel.

Create clickable links to website data in a spreadsheetOpen and edit Microsoft Excel XLSX filesUse a familiar spreadsheet interface for everyday workMove common Office documents between compatible applications
microsoft office alternative - wps office

Frequently Asked Questions

Can I create the hyperlink if the URL is already in a cell?

Yes. Put the plain-text URL in A1 and run the AddWebsiteLink macro from Developer > Macros. The example adds a link labeled Open website in A2.

Why doesn’t Power Query show the URL I need?

The URL may be generated by scripts, hidden behind a login, or unavailable in the source returned to Power Query. Check for an official API or another supported data feed; some sites may require browser automation.

Can I use Internet Explorer automation to retrieve the data?

Internet Explorer automation is obsolete and may not work in current Windows or Excel versions. Prefer an official API, Power Query, an HTTP request, or supported browser automation.

How should I save a workbook that contains the macro?

Choose File > Save As and select Excel Macro-Enabled Workbook (.xlsm) so the VBA code is retained.