vba add hyperlinks dynamically in Excel

Q164. In Excel, how can I dynamically add a hyperlink using VBA?

To do it in Excel, here is the answer:

  1. Option Explicit
  2. Sub AddHyperlink()
  3. ActiveSheet.Hyperlinks.Add Anchor:=Range("AW5"), Address:="http://www.bbc.com", TextToDisplay:="BBC"
  4. End Sub

Description:

a) Line 3 above adds a Hyperlink to Range AW5, with text "BBC". The hyper link links to "http://www.bbc.com".

b) Suppose, the link has to be internal to the WorkBook, say cell A1 in a sheet named "BBC", the command can be modified as below -

ActiveSheet.Hyperlinks.Add Anchor:=Range("AW5"), Address:="", SubAddress:= "BBC!A1", TextToDisplay:="BBC"

 

You can find similar Excel Questions and Answer hereunder

1) How do I update my DropDown list whenever the sheet is activated?

2) How can I copy and rename a WorkSheet using VBA?

3) How can I prevent users from seeing / accessing my macro code?

4) How can worksheet functions be accessed in VBA?

5) How can I remove hyperlinks from a range of cells?

6) How can I add a 3 Month Moving average Trend line to my line chart?

7) How do I enter a formula in a cell using VBA (using Relative Reference)?

8) Vba to return week numbers in Excel

9) How to read a value from a cell in vba in Excel

10) Excel 2010 vba replacement of application filesearch in Excel

11) Line break in vba message box in Excel

12) How can I set the Source Data of charts using VBA?

13) Vba list all files in a folder in Excel

14) How can I activate a routine when there is a change in value of a cell?

15) How can I add a legend to a chart using VBA?