简体   繁体   English

在vba中使用模块类

[英]use module class in vba

I have a module class file "CombinaisonLine" in my class modules folder : 我的类模块文件夹中有一个模块类文件“ 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

In my modules folder, I have a function called when I click on a button in my sheet : 在我的modules文件夹中,当我单击工作表中的按钮时,有一个调用的函数:

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

I am getting an error 91 at line "Line.Adult="1"" with the following message (I am using a french version, so I have translated the message into english): 我在“ Line.Adult =“ 1”“行收到一条错误91,并显示以下消息(我使用的是法语版本,因此我已将该消息翻译成英文):

execution error "91":
Object variable or Bloc variable With not defined

I don't know what I am missing. 我不知道我在想什么。 Thanks in advance for your help 在此先感谢您的帮助

You need to create object of class CombinaisonLine first, and destroy when you do not need it: 您需要首先创建CombinaisonLine类的对象,并在不需要时销毁它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM