Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to catch events of objects in a collection in VBA?

Posted on 2012-09-18
Medium Priority
Last Modified: 2012-09-18
I have defined an class - lets call it SomeClass - with a range of different events.
In order to create a functionality for storing and handling batches of these classes, I have also created a collection class - lets call it SomeClassCollection. Within this the SomeClass objects are stored in a collection.

I would really like to be able to catch the events of individual SomeClass objects in the collection. And let the SomeClassCollection object act accordingly (e.g. by raising its own event). Is this in any way possible?
Question by:andreas_rafn
  • 2
LVL 85

Accepted Solution

Rory Archibald earned 2000 total points
ID: 38409264
If you added a Parent property to the contained class, you could have the child class directly call a method of the parent class for its relevant events.

Author Comment

ID: 38409505
Not a bad idea, did not think of that myself. Regarding performance, I guess that adding a parent will not affect performance much as long as it is passed as a reference. How can I assure that? Is it as simple as adding the ByRef keyword to the set property, e.g.:

Public Property Set Parent(ByRef ParentToSet as SomeObjectCollection)
   Set mParent = ParentToSet 
End Property

Open in new window

LVL 85

Expert Comment

by:Rory Archibald
ID: 38409571
If you pass an object ByVal you only pass a copy of the pointer, not a copy of the object, so I'm not sure how that would affect performance but using ByRef should work.

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question