简体   繁体   English

使用 VBA 向 Excel 中的组合框添加工具提示

[英]Adding a tooltip to a ComboBox in Excel with VBA

I've added two Dropdown (aka ComboBox) to a Sheet我在工作表中添加了两个下拉列表(又名 ComboBox) 在此处输入图片说明

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这是一个 20 秒的剪辑http://www.screencast.com/t/ZbkEOyXntItk

You can get the range of the combobox with application.caller.您可以使用 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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