Background: I have a file, AppLauncher.xlsm, that opens App.xlsm in a new instance of Excel, then closes itself. App.xlsm sets Application.Visible = False, then shows a UserForm. This gives the appearance that the UserForm is its own application, unrelated to Excel.
Issue: If the user manually opens another file, the file is opened in the second instance of Excel (the one with App.xlsm open) and makes the Application visible.
Goal: When the user manually opens a file, open the file in either an already open instance of Excel (if one exists) or a new instance of Excel.
What I've Tried/Researched:
- Using the Application.WorkbookOpen event to capture the manually-opened Workbook's path and name to then close it and open it in a different instance of Excel; this would work, but it doesn't take into consideration another Workbook.xlsm with code using the Workbook.Open event (the Workbook.Open event fires before the Application.WorkbookOpen event).
- Using Access instead of Excel. The VBAWarning registry key is set to 3, requiring all macros to be digitally signed; unfortunately, signing macros in Access appears to be broken.
- Using Word or PowerPoint. I assume I would run into the same issue.
- Running Object Table (ROT). From what I've read, the purpose of ROT is to not create new instances of an application if there's already one running. I've also read that Excel only registers the first instance of Excel in ROT; using RotView, I've observed that multiple instances of Excel are registered, not just the first instance.
Potential Solution: Remove the ROT entry for the instance of Excel that has App.xlsm open... unsure how to accomplish this using only VBA (using the SendMessage function?).
AppLauncher.xlsm code:
Private Sub Workbook_Open()
Call Shell("excel.exe /x /s " & """" & ThisWorkbook.Path & "\App.xlsm""")
ThisWorkbook.Close
End Sub
App.xlsm code:
Private Sub Workbook_Open()
Application.Visible = False
UserForm1.Show vbModeless
End Sub
Edit 1: Using Application.IgnoreRemoteRequests = True
on the instance of Excel that has App.xlsm open does not appear to work in Microsoft 365.