سؤال

I am developing an excel sheet which has lots of ActiveX elements in it. I am not using UserForm and all the data is loaded when an activeX button is pressed.

At this point a hidden excel app is created where various actions are performed.

This new app is then combined with other data etc etc.. based on what the user is doing on the front-end with the provided ActiveX controls.

My problem comes when the "project is reset", where all the objects are released from memory and everything. If this was a user form I would have implemented "on terminate" event where I would close hidden all workbooks that I have used, basically clean after myself.

However this is not a userform and there is no way to detect when the "project is reset"(as far as I know) so the hidden excel app that I've created remain open but nothing points to it.

If I go to the task manager i see various "EXCEL.EXE" and the number of those is basically the number of times I have run the tool.

So, is there any way for me to detect when VBA is about to "stop the project" in the same was as there is "terminate" for user forms so I can delete unsused stuff and reset elements in the spreadsheet?

Thank you!

هل كانت مفيدة؟

المحلول

I have found that there is no corresponding event to catch this.

Best way to handle this is to create a hidden userform object which will "hold" all global variables and objects that I define. I can then implement a UserForm_Deactivate event to catch when the form is exiting and clean up after myself.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top