drj30026abanba
Board Regular
- Joined
- Oct 22, 2015
- Messages
- 83
Hi this is my first time posting on this forum so I hope I am putting this in the right place. I am currently reading MrExcel's "VBA and Macros: Microsoft Excel 2013" and I am having trouble understanding a section in chapter 9 called "Creating a Collection in a Class Module".
Earlier in the chapter a custom object called clsEmployee was created. A class module is then inserted and renamed clsEmployees. Then a private collection is declared in the class module
After that, a few methods are created. Here is one of them
Later in this section, a procedure in a standard module is written to use this collection. It is instantiated like this
and later on the add method is used:
I don't understand why clsEmployees is the name being used to instantiate colEmployees. That is the name of the class module just created. Is the name of the class module always used to instantiate? Why isn't AllEmployees declared Public and used since it is how all the methods are defined?
I don't get why AllEmployees is Private. Also, I don't understand how clsEmployees is related to AllEmployees. AllEmployees looks like a dummy variable but I don't understand how VBA knows that.
I guess my main question is this: When creating a collection with a class module, how is the name of the class module related to the private declaration of a collection?
Earlier in the chapter a custom object called clsEmployee was created. A class module is then inserted and renamed clsEmployees. Then a private collection is declared in the class module
Code:
Private AllEmployees As New Collection
After that, a few methods are created. Here is one of them
Code:
Public Sub Add(recEmployee As clsEmployee)
AllEmployees.Add recEmployee, recEmployee.EmpID
End Sub
Later in this section, a procedure in a standard module is written to use this collection. It is instantiated like this
Code:
Dim colEmployees as New clsEmployees
and later on the add method is used:
Code:
colEmployees.Add recemployee
I don't understand why clsEmployees is the name being used to instantiate colEmployees. That is the name of the class module just created. Is the name of the class module always used to instantiate? Why isn't AllEmployees declared Public and used since it is how all the methods are defined?
I don't get why AllEmployees is Private. Also, I don't understand how clsEmployees is related to AllEmployees. AllEmployees looks like a dummy variable but I don't understand how VBA knows that.
I guess my main question is this: When creating a collection with a class module, how is the name of the class module related to the private declaration of a collection?
Last edited: