Name
commandbarbutton.HyperlinkType [= msoCommandBarButtonHyperlinkType]
Synopsis
Sets or returns a value that determines whether the button represents a normal button, a hyperlink, or a picture file to insert. Can be one of these settings:
msoCommandBarButtonHyperlinkNone (default)
msoCommandBarButtonHyperlinkInsertPicture
msoCommandBarButtonHyperlinkOpen
When msoCommandBarButtonHyperlinkType is set to msoCommandBarButtonHyperlinkInsertPicture or msoCommandBarButtonHyperlinkOpen, the TooltipText property contains the URL of the hyperlink. For example, the following code adds a button to the worksheet menu bar that opens a Google search page:
Sub AddHyperlink( )
Dim cb As CommandBar, cbb As CommandBarButton
' Get a command bar
Set cb = CommandBars("Worksheet Menu Bar")
Set cbb = cb.Controls.Add(msoControlButton, 7343, , , True)
cbb.HyperlinkType = msoCommandBarButtonHyperlinkOpen
cbb.TooltipText = "http:\\www.google.com\"
End SubSimilarly, this code adds a button that inserts an image on the active sheet:
Sub AddInsertPictureButton( )
Dim cb As CommandBar, cbb As CommandBarButton
' Get a command bar
Set cb = CommandBars("Worksheet Menu Bar")
Set cbb = cb.Controls.Add(msoControlButton, 2619, , , True)
cbb.HyperlinkType = msoCommandBarButtonHyperlinkInsertPicture
cbb.TooltipText = ThisWorkbook.Path & "\logo.jpg"
End SubBecome an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access