如何修复“无法获取OLEobject类的Object属性”错误消息?

时间:2019-01-16 05:21:29

标签: excel vba

我在打开Excel时遇到运行时错误'1004',无法获取OLEObject类的对象属性。并且错误发生在代码的***处。我承认我在VBA中的技能是有限的,并且我正在尽我最大的努力使其发挥作用。但是,如果我结束提示的错误消息,则代码运行正常。

我尝试了Sheet1.ComboBox1,但是它不起作用。

Option Explicit

Sub ListBox1_Click()

    Dim CSheet As Worksheet
    Set CSheet = Sheets("CONTROL")

    Dim InfoSheet As Worksheet
    Set InfoSheet = Sheet1

    Dim first_row As Integer
    Dim range_list As Range
    Dim ComboBx As OLEObject
    Set ComboBx = InfoSheet.OLEObjects("ComboBox1")

    ComboBx.Object.Clear ***error occurs here

    If ListBox1.ListIndex = 0 Or ListBox1.ListIndex = 3 Then 
        first_row = 13
    ElseIf ListBox1.ListIndex = 1 Then
        first_row = 5
    ElseIf ListBox1.ListIndex = 2 Then
        first_row = 9
    End If

    Do
    DoEvents

    first_row = first_row + 1
    Set range_list = CSheet.Range("H" & first_row)

    If Len(range_list) > 0 Then ComboBx.Object.AddItem (range_list)
    Loop Until range_list = ""

    ComboBx.Object.ListIndex = 0

End Sub

我在sheet1上有一个activex ListBox1和ComboBox1。我的意图是根据ListBox1动态更新ComboBox1列表。

0 个答案:

没有答案