Insert a Website Hyperlink in Excel Using VBA
Question details
Retrieve website data and a unique URL, then insert the URL as a clickable hyperlink in an Excel worksheet 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.
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.
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.
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.
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.
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
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).

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.

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.




