Creating Worksheets from Existing Excel Instances in VB.NET?

L

leeedw

Hi everyone,

I use the following code whenever I export to Excel from VB.NET

objExcel = New Excel.Application()
objWorkBooks = objExcel.Workbooks
objWorkBook = objWorkBooks.Add
objWorkSheet = objExcel.ActiveWorkbook.ActiveSheet

The problem is that every time I need to export, it results in creating
a new instance of Excel in memory. Excel is a bit of a resource hog,
and suffers from memory leaks. Is there a way to open another
worksheet from an Excel process/instance that is already running if
there is one?

How would I do this?

Thanks!
 
V

+Vice

If objExcel is nothing then
objExcel = New Excel.Application()
End if

Use that code and you won't generate a new Excel application every time.
 
L

leeedw

objExcel is not a global variable and only accessible in this function.
If Excel is already opened manually by the user I would like to use
that instance as well. Is there a way to attach to an existing
process?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top