打开工作簿时无法清除ComboBox值

时间:2016-05-23 10:09:41

标签: vba combobox initialization clear

当我打开我的工作簿时,我想做几件事。其中之一是清除我的Activex控件中的所有值。以下是我的代码

 Public Sub Workbook_Open()

Application.EnableEvents = True
Application.ScreenUpdating = False

Set wb = Application.Workbooks("Incident_Form v11")
Set ws = wb.Sheets("Error Form")

ws.Range("D5").Value = "F&C-3000" &     (Application.WorksheetFunction.RandBetween(1, 1000000000))

ws.ComboBox2.Value = Null
ws.ComboBox3.Value = Null
ws.ComboBox4.Value = Null
ws.ComboBox5.Value = Null
ws.ComboBox6.Value = Null
ws.ComboBox7.Value = Null
ws.ComboBox8.Value = Null
ws.ComboBox9.Value = Null
ws.ComboBox10.Value = Null
ws.ComboBox11.Value = Null
ws.ComboBox12.Value = Null
ws.ComboBox13.Value = Null
ws.ComboBox14.Value = Null
ws.ComboBox15.Value = Null
ws.ComboBox16.Value = Null
ws.ComboBox18.Value = Null

End Sub

出于某种原因,当它到达ws.ComboBox8时,它会发出一个错误,指出'对象不支持此方法或属性'。谁知道为什么?

1 个答案:

答案 0 :(得分:0)

ws.ComboBox8不能与其他人相同,删除,复制并粘贴ws.ComboBox7,并将其重命名为ComboBox8