开发者

Combination button/dropdown in office

开发者 https://www.devze.com 2023-01-27 21:52 出处:网络
How do I开发者_运维问答 add a combination button/dropdown in office (see below). Preferably with code.

How do I开发者_运维问答 add a combination button/dropdown in office (see below). Preferably with code.

Combination button/dropdown in office

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消