Hello. I have created a custom class cTaskPlan in my "TaskPlan" workbook that represents all the data in the workbook. I have a function FillTaskPlan() that creates a new instance of cTaskPlan and populates it with data from the sheet and returns a cTaskPlan object. I'm trying to send out one of these "TaskPlan" workbooks to each team member. Each week I will get the workbook backs. I then want to have a "TaskPlan Aggregator" workbook that i can open, run a macro, it opens each "TaskPlan" workbook and pulls in a populated cTaskPlan object into a collection. Then in the Aggregator file I'll have a collection of all the cTaskPlan objects I can loop through and work with them. I think I have the "TaskPlan" workbook setup correct. From the aggregator, I can open the "TaskPlan" workbook, call the FillTaskPlan() function returning the cTaskPlan object to an object variable. Then I add that to a collection. The problem is, when i close the "TasKPlan" workbook to move on to the next one, the TaskPlan object that was full of data is emptied out. It's as if the object is a reference to an object in the "TaskPlan" workbook and is cleared out upon closing the workbook. Any help would be greatly appreciated. Thanks (Excel 2007)
This is the FillTaskPlan() code in the "TaskPlan" workbook
Public Function FillTaskPlan() As cTaskPlan
Dim thisTaskPlan As cTaskPlan
Set thisTaskPlan = New cTaskPlan
thisTaskPlan.Init
****Code to populate properties of thisTaskPlan
Set FillTaskPlan = New cTaskPlan
Set FillTaskPlan = thisTaskPlan
End Function
This is the code from the "TaskAggregator" workbook. Everything works well. Upon wbTarget.Close... the TaskPlan object is cleared out. I need it to persist.
Sub ProcessFiles()
Dim TaskPlan As Object
Dim TaskPlans As Collection
Dim objFSO As FileSystemObject
Dim objFolder As folder
Dim objFile As file
Dim wbTarget As Workbook
Dim path As String
Set TaskPlans = New Collection
path = "C:\MyFolderPath"
Set objFSO = New FileSystemObject
Set objFolder = objFSO.GetFolder(path)
'Loop through each file adding the cTaskPlan to the collection
For Each objFile In objFolder.Files
Set wbTarget = Workbooks.Open(objFile.path)
Set TaskPlan = Application.Run("'" & wbTarget.Name & "'" & "!FillTaskPlan")
TaskPlans.Add TaskPlan
wbTarget.Close False
Next objFile
End Sub
Bookmarks