Chris Macro
Well-known Member
- Joined
- Nov 2, 2011
- Messages
- 1,345
- Office Version
- 365
- Platform
- Windows
I am running into an interesting scenario with a VBA add-in project. I have a macro that opens up an Excel file, does some stuff, then closes the file. I am running into an issue when this macro is run immediately after someone opens up a blank Excel workbook and has not made any changes to it. In this scenario, Excel acts like Book1 does not exist and the next opened Excel file becomes the only workbook opened. This becomes a problem when my macro goes to close the workbook it had opened.
This scenario does not occur if the users changes anything in Book1 (for example enters a value into cell A1). I'm guessing there is some sort of property value changed telling Excel if Book1 should remain or if it should disappear when another workbook is opened. Is there a way to determine if Excel will keep Book1 or replace it with the next opened workbook? If I can come up with some sort of test, I can then figure out how to prevent a scenario where only the workbook my macro is opening is the only workbook opened.
Hopefully the scenario makes sense. Let me know if you need any more details or clarifications.
This scenario does not occur if the users changes anything in Book1 (for example enters a value into cell A1). I'm guessing there is some sort of property value changed telling Excel if Book1 should remain or if it should disappear when another workbook is opened. Is there a way to determine if Excel will keep Book1 or replace it with the next opened workbook? If I can come up with some sort of test, I can then figure out how to prevent a scenario where only the workbook my macro is opening is the only workbook opened.
Hopefully the scenario makes sense. Let me know if you need any more details or clarifications.