简体   繁体   中英

Adding a tooltip to a ComboBox in Excel with VBA

I've added two Dropdown (aka ComboBox) to a Sheet 在此处输入图片说明

Using this piece of code I can access the Dropdown but how can I add a tooltip on the Dropdown?

The best solution would be to show a different text for every item but if there is only an unique tooltip for the whole dropdown I can change it after selecting every item.

Sub DropDown1_Change()

    Dim s As Object
    Set s = ActiveSheet.Shapes(Application.Caller)
    s.ToolTip = "Example"
    Debug.Print s.ControlFormat.Value

End Sub

This is a forms combobox, it would not have a tooltip capability, but you can make it look like it has a tool tip.

Place a hyperlink with a screen tip underneath the combobox, when you mouse over the combobox the screen tip will pop up. You can place the hyperlink on many cells if you intend on stretching the combobox over many cells.

Like this

在此处输入图片说明

Here is a 20 second clip http://www.screencast.com/t/ZbkEOyXntItk

You can get the range of the combobox with application.caller.

Assign each combobox to this macro, then you would only need one macro.

Sub DoIt()
    Dim r As Range
    r = ActiveSheet.Shapes(Application.Caller).TopLeftCell
    ActiveSheet.Hyperlinks.Add Anchor:=r, Address:=r, ScreenTip:="5435435345", TextToDisplay:="ddddddddddddddddddd"
End Sub

Following is my code:

Private Sub ComboBox1_Click()
   ' Adding new items
   ComboBox1.AddItem ("S")
   ComboBox1.AddItem ("M")

   If ComboBox1.Text = "S" Then  'Add your dropdown item here
   With Me.ComboBox1
   .ControlTipText = "Strong"  ' Add your text here
   End With
   End If
   If ComboBox1.Text = "M" Then   'Add your dropdown item here
   With Me.ComboBox1
   .ControlTipText = "Moderate" ' Add your text here
   End With
   End If

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM