如何让组合框不接受 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 11:45:45  来源:igfitidea点击:

How to get combobox not to accept user input in Excel-Vba?

excelvbacontrolsexcel-2007

提问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