Create and Remove Hyperlinks (from VBA)

Vishesh's picture
Often you have to create and remove hyperlinks at run time. Just paste the following code in a general module:
Sub Create()
    Call CreateHyperlink(Sheet1.Range("A1:A10"))
End Sub
 
Sub Delete()
    Call RemoveHyperlink(Sheet1.Range("A1:A10"))
End Sub
 
Sub CreateHyperlink(rng As Range)
    Dim rngCell As Range
    For Each rngCell In rng
        rngCell.Hyperlinks.Add rngCell, "", , "Screen_Tip", rngCell.Value
    Next rngCell
End Sub
 
Sub RemoveHyperlink(rng As Range)
    rng.Hyperlinks.Delete
End Sub