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 Sub

Similarly, 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 Sub

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.