-
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
-
it would probably be easier, to just create a new instance
-
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
-
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
-
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
-
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
-
you could also work out how to use handles, then you could detect the open windows, and if excel was open
-
thank you reeset. Helped a lot. ;)