防止用户在macrosExcel中正确selectcombobox

我试图在macros中创build用户窗体,并为颜色创buildcomboboxselect。 资源

接口

我已经成功创buildcombobox如下,并防止用户不填充combobox中继续。 这里是代码:

Private Sub UserForm_Initialize() ComboBox1.RowSource = "Sheet1!A1:A" & Range("G" & Rows.Count).End(xlUp).Row End Sub -------------------------------------------- Private Sub CommandButton1_Click() If ComboBox1.Text = "" Then MsgBox "Please Select Color!" Exit Sub Else Sheets("Sheet1").Range("B1").Value = ComboBox1.Value ActiveWorkbook.Close End If 

但是,用户可以在combobox上键入随机文本,我无法阻止它。 有什么办法让用户只能从提供的源select值? 这是事实。

问题

将组合样式设置为fmStyleDropDownList