修复 Combobox 可搜索错误运行时间 70

fix Combobox searchable error run time 70

提问人:Bảo Ngọc Dương 提问时间:10/11/2023 最后编辑:Mayukh BhattacharyaBảo Ngọc Dương 更新时间:10/12/2023 访问量:36

问:

我写了一个可搜索的组合框。但是,我收到运行时错误“70”:权限被拒绝。求求你,帮帮我!

enter image description here

Private Sub cmb_phanloaitheomucdo_12_Change()
    Dim i As Long
    If Not Comb_Arrow Then
        With Me.cmb_phanloaitheomucdo_12
            .List = Worksheets("Sheet1").Range(Sheet1.Range("B2"), Worksheets("Sheet1").Cells(Rows.Count, "B").End(xlUp)).Value
            .ListRows = Application.WorksheetFunction.Min(4, .ListCount)
            .DropDown
            If Len(.text) Then
                For i = .ListCount - 1 To 0 Step -1
                    If InStr(1, .List(i), .text, vbTextCompare) = 0 Then .RemoveItem i
                Next
                .DropDown
            End If
        End With
    End If
End Sub

Private Sub cmb_phanloaitheomucdo_12_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    If KeyCode = vbKeyReturn Then Me.txt_phanloaieau_13.SetFocus
End Sub
Excel VBA ComboBox 用户窗体

评论

0赞 T.M. 10/12/2023
请参阅权限被拒绝错误
0赞 Bảo Ngọc Dương 10/12/2023
不。这对我没有帮助

答:

0赞 taller 10/12/2023 #1

如果正在使用组合框控件的属性,则尝试设置该属性将触发运行时错误 70。RowSourceList

Private Sub CommandButton1_Click()
    Me.ComboBox1.List = Range("D1:E3").Value
End Sub

若要解决此问题,请在设置属性之前添加一行代码以重置属性,或在 VBE 中进行必要的调整。RowSourceList

Private Sub CommandButton1_Click()
    Me.ComboBox1.RowSource = ""
    Me.ComboBox1.List = Range("D1:E3").Value
End Sub

enter image description here