Hyperlinks
Range("B2").Hyperlinks.Add(Anchor:=
Address:=
TextToDisplay:=
Anchor - This can either be a Range or a Shape.
Address - The address of the hyperlink.
SubAddress - The subaddress of the hyperlink
This can be used to create links to cells in the same workbook (eg cells and named ranges)
ScreenTip - The text to display when you hover over with the mouse.
TextToDisplay - The text to display as the hyperlink.
ActiveWorksheet.Hyperlinks.Delete
ActiveWorkbook.FollowHyperlink
Address:="https://bettersolutions.com"
NewWindow:=True
Removing all Hyperlinks
Public Sub RemoveAllHyperlinks()
Dim objworksheet As Worksheet
Dim objhyperlink As Hyperlink
Dim lhypercount As Long
Dim answer
'Set objworksheet = Selection.Parent
answer = MsgBox("Do you want to remove " & Selection.Cells.Hyperlinks.Count & " hyperlinks ?", _
vbQuestion + vbYesNo)
If answer = vbNo Then
Exit Sub
End If
For lhypercount = Selection.Cells.Hyperlinks.Count To 1 Step -1
Set objhyperlink = Selection.Cells.Hyperlinks(lhypercount)
objhyperlink.Delete
Next lhypercount
Call MsgBox("done")
End Sub
Private Sub Worksheet_FollowHyperlink(ByValTarget As Hyperlink)
Call Hyperlink_Activate(Target)
End Sub
Public Sub Hyperlink_Activate(ByVal objHyperlink As Hyperlink)
Dim sScreenTip As String
sScreenTip = objHyperlink.ScreenTip
Select Case sScreenTip
Case "MacroName"
'do something
'maybe even update the ScreenTip
objHyperlink.ScreenTip = "Blah blah"
End Select
End Sub
This can be used to invoke an action or a macro
To create a hyperlink that just takes you to another part of the workbook
right click the cell, choose hyperlink
Select "place in the document" button on the left
In the "type the cell reference" add the cell you want to contain the link
This ensures that the selection doesn't change when the user presses the link.
This links the cell to itself
The following events are raised:
Application.SheetFollowHyperlink
Workbook.SheetFollowHyperlink
Worksheet.FollowHyperlink
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrev