office交流网--QQ交流群号

Access培训群:792054000         Excel免费交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

Excel VBA给Listbox 或ComboBox 设置 时出现权限拒绝70的错误解决办法

2019-11-13 08:35:00
zstmtony
原创
416

Excel VBA给Listbox 或ComboBox 设置 时出现权限拒绝的错误解决办法

英文的错误 提示: Run time error 70: Permission denied


这种情况多数是在Listbox的属性设置中设置了rowsource  属性 或VBA代码中设置了rowsource 属性

然后又使用了Additem 或 设置.list 来设置属性,就会导致这种错误提示

解决办法 :


将属性设置中的 rowsource 属性 设置为空即可



如下面的代码 也是因为属性设置了Recordsource ,所以在下面这句会出现 权限拒绝的错误



Userform1.IbEmp.AddItem rngEmp(i)

The full code is:
Sub Show_Countries()
Dim rngEmp() As String
Dim emps As String
Dim i As Integer

Application.Sheets("Sheet1").Select
emps = ActiveCell.Offset(0, -1).Value
If emps = "" Then
MsgBox ("No Name(s) Available")
End
Else
rngEmp = Split(emps, ",")
End If

I also have codes for buttons in the combo box:


Private Sub closewindow_Click()
Unload Userform1
End Sub

Private Sub reset_Click()
Userform1.IbEmp.Clear
End Sub
Private Sub submit_Click()
Dim emps As String
emps = ""
For i = 0 To Userform1.IbEmp.ListCount - 1
If IbEmp.Selected(i) = True Then
'MsgBox IbEmp.List(i)
If emps = "" Then
emps = IbEmp.List(i)
ElseIf emps <> "" Then
emps = emps & "," & IbEmp.List(i)
End If
End If
Next i
ActiveCell.Value = emps
End Sub


For i = LBound(rngEmp) To UBound(rngEmp)
Userform1.IbEmp.AddItem rngEmp(i)
Next

Userform1.Show
End Sub


以下是微软官网上一个网友遇到的,也是类似的问题 引起的


lb_ExtContacts.List = ar_ListBoxContacts

results in Run-time error 70, permission denied.

What I really want is to change the listbox value based on the click event and to capture the new value in the array, which I'll use later to update cells in a worksheet range.  If there's a more efficient way to do this that doesn't involve refreshing the whole listbox when I change a single item that would be ideal.  But the main thing is I need something that works!  
Here's the code:

Private Sub lb_ExtContacts_Click()
'This routine toggles rows in the listbox as follows:
' If the row status is blank, clicking it changes to
' Active.  If the status is active, clicking changes
' it to Inactive.  If the status is Inactive, clicking
' changes it to Active.  You can't "delete" a row
' using this dialog box.

  With lb_ExtContacts
  
    int_CurrentValue = .ListIndex
  
    Select Case ar_ListBoxContacts(.ListIndex + 1, 4)
      Case Is = "Active"
        ar_ListBoxContacts(.ListIndex + 1, 4) = "Inactive"
      Case Is = "Inactive"
        ar_ListBoxContacts(.ListIndex + 1, 4) = "Active"    
      Case Is = ""
        ar_ListBoxContacts(.ListIndex + 1, 4) = "Active"
    End Select
  End With
  
  lb_ExtContacts.List = ar_ListBoxContacts
  lb_ExtContacts.ListIndex = int_CurrentValue
  lb_ExtContacts.SetFocus

End Sub


分享