How do I开发者_运维问答 add a combination button/dropdown in office (see below). Preferably with code.
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
- manually add icons (GIF, BMP, etc) to the Image list
- manually set the Combo's ImageList property to "ImageList1"
- 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
精彩评论