How can I use vba to modify a Powerpivot connection to a csv file? I have an Excel workbook with a Powerpivot model that connects to a csv file. In the Powerpivot window, I can navigate to the Home->Existing Connections and edit the file path as desired. I can't get close to editing this in vba.
- I found this link on parameterizing Powerpivot connections.
Unfortunately, I couldn't figure out how to modify to apply to csv file connection rather than database connection.
- An alternate approach is described on this page. This approach creates a connection to the data in Excel itself. The connection is then available in Powerpivot. It is critical to not create the connection in Powerpivot bc the author says connections created in Powerpivot cannot be modified by vba.
I can create this connection manually through the
Data->Get External Data->From Text menu option.
I can create the same connection in vba using "Workbooks("myWorkbook.xlsm").Connections.AddFromFile "data.csv". I can manually edit this connection in the Data->Connections->Connections dialog. However, when I try to set this in vba using the WorkbookConnections.TextConnection property, vba says "Object doesn't support this property or method".
The above link focuses on database connections rather than csv file connections. However, it seems possible to set up the csv file with an Microsoft ACE OLEDB 12.0 connection, but I can't quite grasp it.
There are similar questions on SO that address vba modifying pivot sources (like here:Changing pivot table external data source path with Excel macro).
However, I don't want to bring the data into a table in Excel, I want to connect to it so I can work with it in Powerpivot.
I could probably do this with Power Query, but since I already have the csv in the desired format, I'd rather not have to introduce this additional step.
I'm using Excel 2013 64 bit on Windows 7. Thank you for your help.