I'm looking for a macro/vbs to update all the external data query connections to point at a different server or database. This is a pain to do manually and in versions of Excel before 2007 it sometimes seems impossible to do manually.
Anyone have a sample? I see there are different types of connections 'OLEDB' and 'ODBC', so I guess I need to deal with different formats of connection strings?
I ended up writing the following, which prompts for the connection details, creates a connection string, then updates all external data queries to use that connection string.
Even we can refresh particular connection and in turn it will refresh all the pivots linked to it.
For this code I have created slicer from table present in Excel:
This code is for Slicer from DB:
This code is for Slicer created from Excel table present in same workbook:
Common code to create connection and update connection for desired Initial Catalog:
Connection string format is largely irrelevant as Excel will pass it to data providers.
Update one querytable manually, then do something like this:
oledbCn.Connection = ConnectionString causes a crash in excel 2013