I'm learning VBA through Google, YouTube, etc.. and I came across Class Modules.
I have a Tracker Template
.
Every few days I get a report sent to me ("Ice cream FG Inv.xlsm"
)
While trying to understand Class Modules
, I found a template that created a Class Module (within the Tracker Template) WBIceCreamFGINVxlsm
creating a CodeName for all of the worksheets within the Ice Cream FG Inv.xlsm Workbook
.
Example:
Public Property Get wsinventory() As Worksheet
Set wsinventory = Workbook.Worksheets("Inventory")
End Property
In my module, I want to reference wsinventory
, but not understanding exactly how to 'call' the Class Module..
Both Workbooks are Open.
I tried to start with:
Dim Data As Variant
Data = wsinventory.Range("A1").CurrentRegion.Value (**Variable not Defined**)
Then I tried:
Dim wsinventory As Worksheets
With wsinventory
Dim Data As Variant
Data = .Range("A1").CurrentRegion.Value (**Object variable or With variable not set**)
End With
Do I still need to use:
Dim DataSource As Workbook
Set DataSource = Workbooks("Ice Cream FG Inv.xlsm")
With DataSource.Worksheets("Inventory")
End With
If so, what would be the reasoning for using Class Modules?