I’ve got a hidden instance of Excel and am trying to keep it hidden through users double clicking on Workbooks when it is the only instance of Excel running. My solution at present is to catch any Application_WorkbookOpen() and Application_WorkbookNew() events for the hidden instance, and when they happen, do roughly the following:
Dim strWbOpenedName as String, xlNew as New Excel.Application
strWbOpenedName = Wb.path & "\" Wb.name
Wb.Close False
xlNew.Visible = True
xlNew.Workbooks.Open strWbOpenedName
Set xlNew = Nothing
However, despite being made visible, and being the last Excel instance that opened a Workbook, xlNew doesn’t receive subsequent Application_WorkbookOpen events – these still go to the original hidden instance. Does anyone know how I redirect the “main” excel instance to be my newly created one therefore?
I’ve got a horrible suspicion I’ll need to start playing with the Running Objects Table (depending on how Windows chooses the instance of Excel to treat as the one to send opened workbooks to), but don’t really know much about proper management of it (e.g. if that’s how it’s deciding which instance to use, can I just switch out the hWnd of the registered Excel instance with the one available from xlNew without causing the system to fall over?)
It won’t receive any more Application_Open events because it is already open. You could try the following on your hidden instance …
This is working for me with VS2005 and Office 2003 – a bit outdated!