私は従業員(オブジェクト)のコレクションを持ち、各従業員はID、年齢などの独自のプロパティ(属性)を持っています クラスモジュール(clsemployeeという名前)以下のようになります。コレクションのオブジェクトを呼び出す
パブリックID As Integer Public Age As Integer 。 。
そして私は、モジュールに以下のようにコレクションにID、年齢やその他のプロパティを追加しました:
Public Sub employee_collection() ' this collection saves all of the employees records
Dim employee As Collection
Set employee = New Collection
Dim n As Integer
Dim i As Integer
Dim E1 As Variant
Dim j As Integer
n = 528
Dim a, b As String
For i = 3 To n
a = "A" + CStr(i) ' to get the values from the excel sheet
b = "B" + CStr(i)
Set E1 = New clsEmployee
E1.ID = Sheets("A").Range(a).Value ' save the valus of each employee in the collection
E1.Age = Sheets("A").Range(b).Value
employee.Add E1
Next i
End Sub
私は私の他のモジュール(サブ)にどのように呼び出しこのコレクションを知りません。私は価値によってそれを呼び出すべきか、または参照によって呼び出すべきですか?私は、この従業員を私が持っているそれぞれのすべての下位階層で繰り返し定義したくない。
Global employee as Collection
Public Sub employee_collection()
Set employee = New Collection
....'rest of code here
End Sub
Public Sub use_collection()
Debug.print employee.count
End Sub
注意をグローバル宣言はcyboashuで述べたとしても、モジュールにする必要があること:cyboashuが言った時に拡大すること
グローバルに変数にアクセスするには、標準モジュールでグローバル/パブリックを宣言します。 – cyboashu