I am creating an excel Add-In (.xlam
) that needs to selectively respond to workbook/worksheet events, in all open workbooks (user may have multiple workbooks open). I dont want to go down the road of pasting code into other open workbook's ThisWorkbook
modules.
I would like the user to be able to select whether the Add-In will respond to the active workbook's events.
What would be the most appropriate solution to achieve this?
Currently, I am thinking of a solution that looks like this:
Enable the Add-In to listen to application level events via a cls_AppEvents
class (cls_AppEvents
is instantiated on Workbook_open()
).
When user clicks button, add the ActiveWorkbook.Name
to an array of stings. When user clicks button again, remove the 'ActiveWorkbook.Name` from the array.(This would need to be a dynamic array - is there a better option?)
When application-level TableUpdate
(for example) event fires, check the array of workbook names to see if it contains the Workbook's name where the event originated. If so, call whatever function.