VBA - Determine If Book1 Remain Or Disappear when opening another file

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,345
Office Version
  1. 365
Platform
  1. 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.
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top