I just finished a macro to look through a named range on a worksheet and add or remove a cell pattern based on a "hide" or "show" code in the first column. This macro is called by the Workbook_SheetActivate and Workbook_SheetChange event handlers coded in the macro's ThisWorkbook sheet. So when ever a cell is changed, the macro is called and resets the pattern based on any changes to the hide or show codes. This seems to work well when I place test code in the macro's (.xlsm) file. However, once I save this as an .xlam file and install it as an addin, it does not function when a new spreadsheet is loaded.
If I manually add the Workbook_SheetActivate and Workbook_SheetChange events to this new spreadsheet's Thisworkbook sheet, then it does apprear to try to call the macro.
So the questions I have are:
1. Is there some reason why the calls in the macro's ThisWorkbook sheet are not functioning (or is that by design) when running as an Addin macro? (I have other code for Workbook_Open in that macro that works, but it only gets called on open, not every change...)
2. Can I progammatically open the new spreadsheet's ThisWorkbook sheet and write the Sub Workbook_SheetChange macro (it's only about 3 lines)? It's OK if that programmatically built code is lost when the file is closed -- in fact, I would like to remove it on close if it doesn't.
Does anyone know how to do that or have a better idea for what I'm trying to accomplish?
Thanks!
If I manually add the Workbook_SheetActivate and Workbook_SheetChange events to this new spreadsheet's Thisworkbook sheet, then it does apprear to try to call the macro.
So the questions I have are:
1. Is there some reason why the calls in the macro's ThisWorkbook sheet are not functioning (or is that by design) when running as an Addin macro? (I have other code for Workbook_Open in that macro that works, but it only gets called on open, not every change...)
2. Can I progammatically open the new spreadsheet's ThisWorkbook sheet and write the Sub Workbook_SheetChange macro (it's only about 3 lines)? It's OK if that programmatically built code is lost when the file is closed -- in fact, I would like to remove it on close if it doesn't.
Does anyone know how to do that or have a better idea for what I'm trying to accomplish?
Thanks!