Click to See Complete Forum and Search --> : How to get the open Excel-instances?


elw6mire
August 6th, 2001, 07:27 AM
I save different data in Excel-files from my VB-application.
I access Excel through the following object variable:

Dim xlApp as Excel.Application
Set xlApp = CreateObject("Excel.Application")

Is there a way to determine whether xlApp is instantiated or how many instances have been created?

Unfortunately IF xlApp = Nothing Then ... doesn't work.

I want to make sure, that I can close all the Excel-instances in case of an error.

Michael

Cimperiali
August 6th, 2001, 09:49 AM
Now, if you are concerned about the object you create in your application,
...if isObject(xlapp) then... should be enough as long as the scope of your object is enough general to be recognized where you write this code (ie: you may dim the variable in general section of your form and then use createobject inside a private sub. In another private sub of same form you could test for this variable to contain an object). However, if somewhere you make excell visible and so user may close it via Excell itself, you may know it if you change to early binding and declare the xlapp withevents, and then code the Quit event. Beware: there'is a difference in the triggering of this event from Vb Ide to Compiled program (in Ide it will not trigger when you close excell from your code)...


Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, TCartwright, Bruno Paris
and all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.

The Rater