【发布时间】:2012-12-24 18:46:44
【问题描述】:
我已经创建了名为“class1”的类:
Private ka As Variant
Private ra As Variant
Public Property Get kolom() As Variant
kolom = ka
End Property
Public Property Get rij() As Variant
rij = ra
End Property
Public Property Let kolom(value As Variant)
ka = value
End Property
Public Property Let rij(value As Variant)
ra = value
End Property
然后在一个普通的模块子中我定义了变量:
Public Sub MakeArray(OutputSheet As Variant)
Dim igeg As Class1
Set igeg = New Class1
igeg.kolom = 47
igeg.rij = 559
End Sub
现在在一个新的 sub 中,我想获得 47 和 559 的值,但我不知道该怎么做。我尝试了以下方法,但 ik 没有给出任何价值:
sub test()
Dim igeg As Class1
newkolom = igeg.kolom
Msgbox igeg.kolom
End sub
或尝试以下但没有结果:
Public Function Test1() As Class1
Set Test1 = New Class1
End Function
Public Sub test()
Dim newigeg As Class1
Set newigeg = Test1
Msgbox igeg.kolom
End sub
其实我的想法是我想在另一个 sub 中使用 sub 1 中计算的值。我如何从类模块中获取价值或有更好的方法。不想使用调用 sub(value)。
提前感谢您的帮助!
阿米尔
【问题讨论】:
-
请看一下我给出的两种方法的答案。 :) 试用后请评论。
-
@Amit 我给完整的问题 +1,因为你已经展示了正确的相关代码。这有助于通过最可能的答案来公正地解决您的问题:)
标签: class excel module subroutine vba