办公室中的组合按钮/下拉菜单 [英] Combination button/dropdown in office

查看:109
本文介绍了办公室中的组合按钮/下拉菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在办公室中添加组合按钮/下拉菜单(请参见下文).最好带有代码.

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

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

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

推荐答案

您可以基于以下ActiveX控件来做到这一点:

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

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

手动从[控件工具箱]菜单栏中选择更多控件...",然后双击提到的控件以将其放置在工作表上.将ComboBox放置在所需的位置,而忽略ImageList的位置,它仅在设计模式下可见.到目前为止,您有两个名为

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

插入两个组件也会创建对... \ system32 \ MSCOMCTL32.OCX的引用.

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

那你

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

现在,您的Combo带有错误但没有图标.

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

然后执行此代码

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创建时的行为似乎有所不同

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 ....

创建了组合,但是无论我做什么,下拉箭头都不会显示,尽管调试器显示所有ListView元素都已整齐地附加.许多同事似乎对该ActiveX存有疑问,网上有大量发布信息.

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.

进一步阅读此处

这篇关于办公室中的组合按钮/下拉菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆