Results 1 to 8 of 8

Thread: use an existing instance of excel

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Brazil
    Posts
    14

    Exclamation

    Hi guys!

    I have a problem here. I am exporting the contents of an ADO recorset to an Excel Sheet, and I want to know if there is a way of using an existing excel window wich is already opened to create the new sheet or is it really necessary to create a new instance of the Excel.Application object.

    Thank you in advance
    by Ramosf

  2. #2
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    it would probably be easier, to just create a new instance

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Brazil
    Posts
    14

    Thumbs up

    yes, I know that instantiating again is much easier, in fact that´s what I am doing now.

    But in my case it would really be nice if I could use the already opened instance, because my application export data very often and opening excel on every time isn´t a good idea, right?

    Just wanted to know if there´s a way


    thank you anyway
    by Ramosf

  4. #4
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    you could open one excel instance for the duration of the execution of your application. I.e at the start open it, when it's closed, close it and maybe have it invisible

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Brazil
    Posts
    14
    yeah, that would solve, I´ve already thought about it, but what I want to know is if it is possible, you see, I can work my problem out, I just want to do THAT WAY
    by Ramosf

  6. #6
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    You would use the GetObjects command to get an opened version of excel. However, this will take the first opened instance of excel, so if there is more then one version opened, then you might run into problems.

    Code:
    Private Sub Command2_Click()
    
    Dim objExcel As Excel.Application
    Dim objWorkSheet As Excel.Workbook
    Dim objSheet As Excel.Worksheet
    
    Set objExcel = GetObject(, "Excel.Application")
    Set objSheet = objExcel.ActiveWorkbook.ActiveSheet
    
    objSheet.Range("A1").Value = "hi"
    DoEvents
    objExcel.Quit
    
    
    End Sub

  7. #7
    Conquistador
    Join Date
    Dec 1999
    Location
    Australia
    Posts
    4,527
    you could also work out how to use handles, then you could detect the open windows, and if excel was open

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Location
    Brazil
    Posts
    14
    thank you reeset. Helped a lot.
    by Ramosf

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