类属性错误VBA
运行一个简单的类操作代码时,我得到了runtine错误91:Object Vrable或With block variable not set 这是我的课 cTask:类属性错误VBA,vba,excel,excel-2010,Vba,Excel,Excel 2010,运行一个简单的类操作代码时,我得到了runtine错误91:Object Vrable或With block variable not set 这是我的课 cTask: Private pMile As cMile Public Property Get Mile() As cMile Set Mile = pMile End Property Public Property Set Mile(Value As cMile) Set pMile = Value End Pro
Private pMile As cMile
Public Property Get Mile() As cMile
Set Mile = pMile
End Property
Public Property Set Mile(Value As cMile)
Set pMile = Value
End Property
Private Sub Class_Initializer()
Set Me.Mile = New cMile
End Sub
cMile:
Private pstatus As String
Public Property Get status() As String
status = ppstatus
End Property
Public Property Let status(Value As String)
pstatus = Value
End Property
以及小组:
Sub testt()
Dim ct As New cTasks
ct.Mile.status = "compl"
Debug.Print ct.Mile, ct.Mile.status
End Sub
代码从sub转到cTask中的get属性。当即将执行“结束属性”行时,会弹出错误
我想我的课一定有问题,但我不知道是什么。我最近刚开始使用类。有什么想法吗
谢谢您有一个打字错误:
Class_Initializer()
应该是
Class_Initialize()
这会阻止创建ct
的Mile
,因此访问它会引发您看到的错误
ppstatus
拼写也不正确。Debug.Print ct.Mile
不起作用,就像您要打印工作表.Name
。您必须指定哪个工作表工作表(1).Name
。为此,工作表
必须是工作表的集合,因此可能英里
也应该是工作表的集合。但是我可以为一个给定的ct设置不同的类cMile,然后为每个ct设置多个属性状态吗?我想我的问题是如何在没有其他cMile的情况下在cTask中重新初始化一个新的cMile类,以及如何在子文件中命名它而不丢失另一个cMile如果你改正了,就不要跟着做。迈尔应该没问题