tags:

views:

17

answers:

1

I have a program that filters data and then outputs it to a tabg delimited file. I then use Excel Interop to open this file in Excel because directly outputting to a worksheet takes too long. So currently I am using this code:

    AD.DF.WriteToFile(vbTab)
    Dim WB As Workbook = ExcelApp.Workbooks.Open(AD.DF.DatafileInfo.WriteToFileLocation)
    ExcelApp.Visible = True

The first line takes the filtered data and outputs to a tab delimited file. The second opens that same file in a new workbook in Excel. And obviously the third makes Excel visible. Here is my problem though: right now when this code is run there are two open workbooks. I already have an active workbook and I would just like to open this file to that workbook.

If this is possible, how do I do it? Thank you.

A: 

Look at the GetObject function.

Dim MyXL As Object
MyXL = GetObject(, "Excel.Application")

should get you a reference to the currently running instance of Excel.

Mark