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

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,341
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.
 

Forum statistics

Threads
1,078,495
Messages
5,340,704
Members
399,390
Latest member
newexcel12

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top