Excel - 通过VBA显示ComboBox DropDown

时间:2022-11-19 22:35:07

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

我需要一个工作簿来打开时显示Combobox列表下拉列表。

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

工作簿中的组合框是一个表单控件,因此是一个形状。

Cant seem to find the associated property.

似乎找不到相关的财产。

3 个解决方案

#1


5  

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

如果您使用的是ActiveX控件,请参阅下面的内容,否则如果您使用的是表单控件,则将其替换为ActiveX控件(如果您希望通过代码进行下拉菜单)。下面的代码适用于表单和工作表中的ActiveX控件。如果控件位于工作表上,则将ComboBox1.SetFocus更改为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.
  • 使用Sendkeys。如果使用不当,Sendkeys是不可靠的。

Tried And Tested

经过试验和测试

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

SCREENSHOTS

Excel  - 通过VBA显示ComboBox DropDown

#2


0  

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

我有很多崩溃与.dropdown但发现SendKeys取得了一些成功...

#3


0  

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

我认为最好的UserForm组合框如上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

对于工作表上的一些组合框CB.DropDown就够了..就像他们没有setfocus或激活一样

#1


5  

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

如果您使用的是ActiveX控件,请参阅下面的内容,否则如果您使用的是表单控件,则将其替换为ActiveX控件(如果您希望通过代码进行下拉菜单)。下面的代码适用于表单和工作表中的ActiveX控件。如果控件位于工作表上,则将ComboBox1.SetFocus更改为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.
  • 使用Sendkeys。如果使用不当,Sendkeys是不可靠的。

Tried And Tested

经过试验和测试

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

SCREENSHOTS

Excel  - 通过VBA显示ComboBox DropDown

#2


0  

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

我有很多崩溃与.dropdown但发现SendKeys取得了一些成功...

#3


0  

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

我认为最好的UserForm组合框如上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

对于工作表上的一些组合框CB.DropDown就够了..就像他们没有setfocus或激活一样