i am using the excel engine behind the scenes in my vb.net application. i intend for the user never to see excel directly.
in most cases, this works great. the application, workbook, and sheets, etc all open and close invisibly. the only clue to excel running is in the process window of the task manager.
while my vb.net app is running, if the user starts excel, a new excel session can run, work, and close, still keeping mine hidden.
however, if the user double-clicks on an existing .xls file, the os finds my excel process, and opens the users sheet using my excel process. the problem here is that my workbook now appears on the taskbar, confusing the user. the user, closes the unrecognized workbook (at best), rendering my application unusable.
does anyone know how i might protect myself from this? as a first step, i've set my sheets to xlSheetVeryHidden, such that my workbook looks empty. this of course helps the user feel all the more comfortable in closing it.
other ideas? thanks.
04-23-2004, 12:34 PM
Yes, preventing the User from "hijacking" your Excel instance is relatively easy. Assuming that the Object Variable that is holding your Excel.Application instance is named 'oExcel', then all you would need to call is oExcel.IgnoreRemoteRequests = True :),
thanks mike for the response. that did indeed stop the os from hijacking my excel process.
though now, the os displays an error when double-clicking on any .xls while my app is running. the error is basically, "cannot find the document or one of its components", then "the document refers to an object that is unavailable". that makes sense to me, but will confuse my user.
which to choose?
04-23-2004, 01:35 PM
That is really unfortunate. :(
In VBA or when using VB 6.0 Automation, this command will successfully shield your Application from being "Hijacked" while still allowing the User full access to NEW Excel.Application instances. That is, if the User were to double-click on any .xls icon whily your VBA or VB6 App were running, then a NEW version if Excel would open for the User. Your app would remain Hidden and so the User would not even be aware that your instance is running at all. They would notice no changes.
Somehow it seems that .Net's COM Interop is causing Excel's behaviour to change from what is known as 'Single-Use' to 'Multi-Use'. In 'Single-Use' new instances are spawned by any new Host making use of the 'New' Keyword or CreateObject() function. 'Multi-use' would imply that all hosts/users are using the same instance of the Class. (Outlook is Mult-use, while Excel, Word and Accesss are all Single-Use.)
I don't know why this is happening within VB.Net... But there are some issues with the COM Interop, and I guess this is one of them. I wish I could help here. If you do get it figured out, please come back and let us know how you handled it so that we can pass on your Wisdom to anyone else who may come by that is trying to deal with the same issue...
If we can't *fix* the problem, then all I can suggest is that you do the following:
(1) Make your Workbook an XLA Addin. That way it is effectively "Very Hidden". The user will not be able to see it operating, even if they do open up Excel. This can be be easily accomplished with oWorkbook.IsAddin = True It's up to you if you want to save it with .IsAddin = True, but you probably do, in my opinion.
(2) Make use of the Workbook_BeforeClose() Event or possibly the Application_WorkbookBeforeClose() Event to allow your own code to close your workbook, and not the User.
If the User is trying to close your workbook, then they are actually trying to Close Excel. In this case I would (a) close all open workbooks other than your own, and (b) call oExcel.Visible = False. The result of this is that it will look to the User that Excel has closed, but in reality, your Workbook will still be alive & running in the background...
I hope this makes sense?
[Edit: Hmmm... this leaves the problem of Windows Shutdown, where in this case your program will be preventing Excel from closing...
Ok, I've got it: If you trap a Workbook_BeforeClose() event then:
If oExcel.Visible = True then:
' Close all workbooks other than yours
' and let oExcel.Visible = False.
' oExcel.Visible = False, so the User is closing out your Excel Application
' via a Windown Shutdown. In this case call oExcel.Quit (after saving
' your workbook if that is required).
End if-- Mike]