CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2001
    Posts
    1

    How to get the open Excel-instances?

    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



  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: How to get the open Excel-instances?

    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
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured