locked
Reuse WorkbookConnection for another ListObject? RRS feed

  • Question

  • Hi,

    in my VSTO Excel-Add In i add a workbook connection by calling the Connections.Add Method:

    Globals.ThisAddIn.Application.ActiveWorkbook.Connections.Add

    The resulting WorkbookConnection Object is then getting passed to the ListObjects.Add Method like this

    Globals.ThisAddIn.Worksheet.ListObjects.AddEx(0, oConnection, True, 1, Globals.ThisAddIn.Application.ActiveCell)

    I then modify the resulting ListObject.QueryTable to match my requirements which works fine.

    Question: How can i reuse the existing WorkbookConnection for ANOTHER ListObject or QueryTable. Is this possible at all or does any ListObject or QueryTable need their own WorkbookConnection?

    => I simply want to display 2 or more different queries coming from the same data source.

    Thanks,

    Michael


    Michael Sommer

    Wednesday, October 2, 2013 10:42 AM

All replies

  • Hi Michael.

    Try to get an existing connection like this:

    Microsoft.Office.Interop.Excel.OLEDBConnection oc = app.ActiveWorkbook.Connections.Item(0).OLEDBConnection;
    You can reset OLEDBConnection Properties.

    Thursday, October 3, 2013 7:29 AM