如果我设置 .RowSource
ListBox 的属性到 命名范围 然后在用户窗体的 VBA 显示和用户窗体的 Excel 显示中都可以选择行源。但是,使用 ComboBox 时,我只能在 VBA 显示屏上看到它。如果在设置 .RowSource
之后我尝试的属性(property).AddItem
到我得到的 ComboBox 对象 run time error 70, permission denied
.
Private Sub UserForm_Initialize()
With pres_unit
.AddItem "kPa"
.AddItem "bar"
End With
End Sub
如何使用命名范围作为 ComboBox 下拉选项的来源?
最佳答案
如果您使用的是 NamedRange
对于单个列,您可以使用 List
的属性(property)组合框 :
Private Sub UserForm_Initialize()
' create the Named Range "myNameRange"
' you can manually (or with variables) modify the Range("B2:B10") in "Sheet1"
ThisWorkbook.Names.Add "myNameRange", Sheets("Sheet1").Range("B2:B10")
With pres_unit
.List = Range("myNameRange").value
'disallows user input, only values from list
.Style = fmStyleDropDownList
End With
End Sub
关于excel - 属性 "RowSource"无法在组合框中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39304165/