Dim newCIS As CIS
Dim newString As String
Private Sub CommandButton1_Click()
newString = "lol"
newCIS.ContactName = newString
UserForm1.Label1.Caption = newCIS.ContactName
End Sub
我在第6行遇到错误91.这是CIS类:
Private strContactName As String
Property Let ContactName(name As String)
Set strContactName = name
End Property
Property Get ContactName() As String
Set ContactName = strContactName
End Property
我也尝试过使用set函数而不是属性let,但这也会导致错误91.在vba中我是否缺少一些关于面向对象编程的重要知识?
答案 0 :(得分:4)
您忘了创建该类的新实例:
Private Sub CommandButton1_Click()
newString = "lol"
Set newCIS = New CIS
newCIS.ContactName = newString
UserForm1.Label1.Caption = newCIS.ContactName
End Sub