如何让组合框不接受 Excel-Vba 中的用户输入?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7006888/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get combobox not to accept user input in Excel-Vba?
提问by Vivian
Does anyone know what the properties are in the combobox that I can manipulate in order not to allow the user to key/type in any data?
有谁知道我可以操纵的组合框中的属性是什么,以便不允许用户键入/键入任何数据?
回答by Jacob
Set the the Style of the combobox to 2 - fmStyleDropDownList
. This will disallow user input, and will also prevent (combobox).value changes via macro.
将组合框的样式设置为2 - fmStyleDropDownList
。这将禁止用户输入,并且还将阻止 (combobox). 通过宏更改值。
回答by Esmu Igors
YourComboBoxName.Style = fmStyleDropDownList
or
或者
YourComboBoxName.Style = 2
(that's from MS Excel Help)
(来自 MS Excel 帮助)
回答by enderland
Here's a way to change this for each object on a worksheet:
这是为工作表上的每个对象更改此设置的方法:
Private Sub fixComboBoxes()
Dim OLEobj As OLEObject
Dim myWS As Worksheet
Set myWS = Sheet1
With myWS
For Each OLEobj In myWS.OLEObjects
If TypeOf OLEobj.Object Is MSForms.ComboBox Then
OLEobj.Object.Style = fmStyleDropDownList
End If
Next OLEobj
End With
End Sub