办公室中的组合按钮/下拉菜单

发布于 2024-10-05 06:03:50 字数 154 浏览 0 评论 0原文

如何在 Office 中添加组合按钮/下拉菜单(见下文)。最好有代码。

alt text

更新: 如果有帮助,则不需要代码。

How do I add a combination button/dropdown in office (see below). Preferably with code.

alt text

Update: If it helps any, code isn't needed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时间你老了 2024-10-12 06:03:50

您可以这样做,基于以下 ActiveX 控件:

  • Microsoft ImageList 控件,版本 6
  • Microsoft ImageComboBox 控件,版本 6

手动,从[控件工具箱]菜单栏中选择“更多控件...”,然后双击提到的控件即可把它们记在你的表上。将 ComboBox 放置在您想要的位置,并忽略 ImageList 的位置,它仅在设计模式下可见。现在您已经有两个名为

  • ImageList1
  • ImageCombo1

的嵌入式控件。这两个组件的插入还会创建对 ...\system32\MSCOMCTL32.OCX 的引用。

然后

  1. 手动将图标(GIF、BMP 等)添加到图像列表中
  2. 手动将 Combo 的 ImageList 属性设置为“ImageList1”
  3. 手动将 Combo 的 AutoLoad 属性设置为 True

现在您有一个出现错误但没有图标的 Combo。

然后你执行这段代码

Sub FillCombo()
Dim SH As Worksheet, OO As OLEObjects, Idx As Integer

    Set SH = ActiveSheet
    Set OO = SH.OLEObjects


    With OO("ImageCombo1").Object
        .ComboItems.Clear
        For Idx = 1 To OO("ImageList1").Object.ListImages.Count
            .ComboItems.Add , , , Idx
        Next Idx
    End With

End Sub

我已经尽力通过VBA创建对象,但是ImageCombo在创建时似乎表现不同,因为

Set SH = ActiveSheet
Set OO = SH.OLEObjects
OO.Add "MSComctlLib.ImageComboCtl.2"
' .... etc ....

创建了组合,但是无论我做什么,下拉箭头都不会显示,尽管调试器显示所有ListView 元素整齐地连接在一起。很多同事似乎都对 ActiveX 有问题,网上有很多帖子。

进一步阅读此处

you can do it, based on the following ActiveX controls:

  • Microsoft ImageList Control, Version 6
  • Microsoft ImageComboBox Control, Version 6

Manually, you select "More Controls..." from the [Control Toolbox] menu bar and double click the mentioned controls to get them on your sheet. Position the ComboBox where you want it to be, and disregard the position of the ImageList, it is visible only in design mode. By now you have two embedded contros named

  • ImageList1
  • ImageCombo1

The insertion of the two components also creates a reference to ...\system32\MSCOMCTL32.OCX.

Then you

  1. manually add icons (GIF, BMP, etc) to the Image list
  2. manually set the Combo's ImageList property to "ImageList1"
  3. manually set the Combo's AutoLoad property to True

By now you have a Combo with the error but no icons.

Then you execute this code

Sub FillCombo()
Dim SH As Worksheet, OO As OLEObjects, Idx As Integer

    Set SH = ActiveSheet
    Set OO = SH.OLEObjects


    With OO("ImageCombo1").Object
        .ComboItems.Clear
        For Idx = 1 To OO("ImageList1").Object.ListImages.Count
            .ComboItems.Add , , , Idx
        Next Idx
    End With

End Sub

I've tried hard to create the objects by VBA, but the ImageCombo seems to behave different when created as

Set SH = ActiveSheet
Set OO = SH.OLEObjects
OO.Add "MSComctlLib.ImageComboCtl.2"
' .... etc ....

The combo is created, but the dropdown arrow is not displayed no matter what I do, allthough debugger shows that all ListView elements are neatly attached. Lots of colleagues seem to have problems with that ActiveX, there's loads of posting on the net.

Further reading here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文