gpt4 book ai didi

vba - 在vba中使用模块类

转载 作者:行者123 更新时间:2023-12-03 02:44:47 27 4
gpt4 key购买 nike

我的类模块文件夹中有一个模块类文件“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

在我的模块文件夹中,当我单击工作表中的按钮时,我会调用一个函数:

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

我不知道我错过了什么。预先感谢您的帮助

最佳答案

需要先创建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

关于vba - 在vba中使用模块类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28602634/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com