代码之家  ›  专栏  ›  技术社区  ›  Revious

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

  •  1
  • Revious  · 技术社区  · 7 年前

    我已经添加了两个下拉列表(又名组合框)到一个工作表 enter image description here

    使用这段代码,我可以访问下拉菜单,但我如何才能添加一个下拉菜单上的工具提示?

    最好的解决方案是为每个项目显示不同的文本,但如果整个下拉列表只有一个唯一的工具提示,我可以在选择每个项目后更改它。

    Sub DropDown1_Change()
    
        Dim s As Object
        Set s = ActiveSheet.Shapes(Application.Caller)
        s.ToolTip = "Example"
        Debug.Print s.ControlFormat.Value
    
    End Sub
    
    1 回复  |  直到 6 年前
        1
  •  5
  •   Davesexcel    7 年前

    这是一个窗体组合框,它没有工具提示功能,但您可以使它看起来像有工具提示一样。

    在组合框下面放置一个带有屏幕提示的超链接,当您将鼠标移到组合框上时,屏幕提示将弹出。

    enter image description here

    这是一个20秒的剪辑 http://www.screencast.com/t/ZbkEOyXntItk

    将每个组合框指定给此宏,则只需要一个宏。

    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
    
        2
  •  0
  •   RamanaRaju    7 年前

    以下是我的代码:

    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
    
    推荐文章