I have VBA in a workbook that executes a large amount of code when the workbook is opened, under Private Sub Workbook_Open()
After executing the code, the workbook stayed open. I run a scheduled task every night that opens the workbook in a new instance of excel, so the code gets executed. The problem arose if the workbook was open when the scheduled task ran -- since the code was set to execute ON OPEN, none of it executed since the workbook was already open.
So, I set forth to put in an ActiveWorkbook.Close True statement at the bottom of the Private Sub Workbook_Open() subroutine. That does the task too well -- I can't open the workbook anymore.
I'd really appreciate any help. Ideally, I would like for the workbook to be closed if it were opened in a new instance of excel, but to stay open if opened in an already existing excel instance.
Thank you
After executing the code, the workbook stayed open. I run a scheduled task every night that opens the workbook in a new instance of excel, so the code gets executed. The problem arose if the workbook was open when the scheduled task ran -- since the code was set to execute ON OPEN, none of it executed since the workbook was already open.
So, I set forth to put in an ActiveWorkbook.Close True statement at the bottom of the Private Sub Workbook_Open() subroutine. That does the task too well -- I can't open the workbook anymore.
I'd really appreciate any help. Ideally, I would like for the workbook to be closed if it were opened in a new instance of excel, but to stay open if opened in an already existing excel instance.
Thank you