在vba中使用模块类
我在我的课程模块文件夹中有一个模块类文件“CombinaisonLine”:
Private pAdult As String Private pChild As String Public Property Get Adult() As String Adult = pAdult End Property Public Property Let Adult(Value As String) pAdult = Value End Property Public Property Get Child() As String Child = pChild End Property Public Property Let Child(Value As String) pChild = Value End Property
在我的模块文件夹,我有一个函数,当我点击我的工作表中的一个button:
Function Test() Dim Line As CombinaisonLine If (Sheets("Feuil1").Cells(3, 6).Value = "YES") Then Line.Adult = "1" Line.Child = "0" End If End Function
我在线路“Line.Adult =”1“”中收到错误91,并带有以下消息(我正在使用法语版本,所以我已将消息翻译成英文):
execution error "91": Object variable or Bloc variable With not defined
我不知道我错过了什么。 在此先感谢您的帮助
你需要首先创buildCombinaisonLine类的对象,并在你不需要的时候销毁:
Function Test() Dim Line As CombinaisonLine Set Line = New CombinaisonLine If (Sheets("Feuil1").Cells(3, 6).Value = "YES") Then Line.Adult = "1" Line.Child = "0" End If Set Line = Nothing End Function