Home » excel » sql – MS Excel – existing connection strings correspond to which datatable

sql – MS Excel – existing connection strings correspond to which datatable

Posted by: admin May 14, 2020 Leave a comment

Questions:

I have an excel spreadsheet that has 8 connections. I would like to know what connection string corresponds to which datatable/pivot table in excel. A solution in 2007 or 2010 method is fine.

Is this possible?

How to&Answers:

It is possible using the Data tab.

Try this:

— Click on Connections in the Data tab to bring up the Workbook Connections dialog.

Excel Data --> Connections

— Click on a connection in the list.

List of Workbook Connections

— Click the link: click here to see where the selected connections are used

Show where data connections are used in Workbook

Answer:

This is possible from VBA too. This query just enumerates them.

You can readily modify this example to refresh the queries using PivotCache.Refresh or QueryTable.Refresh.

Sub ShowAllQueryConnectionStrings()
    Dim oSheet As Excel.Worksheet
    For Each oSheet In Application.ActiveWorkbook.Sheets
        Dim oTable As Excel.QueryTable
        For Each oTable In oSheet.QueryTables
            Debug.Print "QueryTable " & oTable.Name & ": " & oTable.Connection
        Next
        Dim oPivot As Excel.PivotTable
        For Each oPivot In oSheet.PivotTables
            Debug.Print "PivotTable " & oPivot.Name & ": " & oPivot.PivotCache.Connection
        Next
    Next
End Sub