Excel - Display ComboBox DropDown by VBA

2019-07-23 02:14发布

I need a workbook to display the Combobox List Dropdown when it opens.

The combobox in the Workbook is a form control, so a shape.

Cant seem to find the associated property.

3条回答
Emotional °昔
2楼-- · 2019-07-23 02:54

If you are using ActiveX Controls then see the below, else if you are using Form Controls then replace them with ActiveX Controls if you want the drop down to happen via code. The below code will work for both ActiveX Controls in a Form as well as Worksheet. If the Control is on a worksheet then change ComboBox1.SetFocus to ComboBox1.Activate

Two ways I can think of...

  • Using a simple command

Tried And Tested

Private Sub CommandButton1_Click()
   ComboBox1.DropDown
End Sub
  • Using Sendkeys. Sendkeys are unreliable if not used properly.

Tried And Tested

Private Sub CommandButton1_Click()
   ComboBox1.SetFocus
   SendKeys "%{Down}"
End Sub

SCREENSHOTS

enter image description here

查看更多
smile是对你的礼貌
3楼-- · 2019-07-23 03:03

I consider best UserForm combo box is as Above by Siddharth Rout ComboBox1.SetFocus SendKeys "%{Down}"

for some Combo boxes on a worksheets CB.DropDown Is enough .. Just as well as they have no setfocus or activate

查看更多
欢心
4楼-- · 2019-07-23 03:09

I have had plenty of crashes with .dropdown but find some success with the SendKeys...

查看更多
登录 后发表回答