How can I make reference to the ThisWorkbook object in workbook 1 from the code in a module in workbook 2 in Excel 2013?
I have 2 workbooks open and I need to delete 4 lines of code from the ThisWorkbook Object in the other workbook. The reason for this is because the 4 lines of code are in the On Deactivate event and when the other workbook gets the focus the event runs. I connot turn off events or the event in workbook 2 won't run when they are supposed to. I had hoped it I activated workbook 1 that it would reference the correct vbaproject, but it doesn't. Here's the code I tried:
I tried numerouse variations but I can only seem to delete the lines of code from the workbook that the macro is running from (workbook 2)![]()
Workbooks(WkBkB).Activate strname = VBAProject.ThisWorkbook.CodeName ThisWorkbook.VBProject.VBComponents(strname).CodeModule.DeleteLines 1, 4
I'm out of ideas! Please help
Bookmarks