Is it possible to have a connection string depend on a cell value or a named formula in an .xlsx
file (i.e. non-macro enabled sheet)?
Background:
Every month I create a new workbook and update the external data source. This way I have workbooks with the results for each month and can always go back to look at a past month's data.
Now, since I use multiple pivot tables on the same data, I use a data connection. The connection string looks something like this, of which the data source is the relevant one.
Provider=Microsoft.ACE.OLEDB.12.0;
User ID=Admin;
Data Source=C:\pathtofile\myworkbook1705.xlsx;
Mode=Share Deny Write;
Extended Properties="HDR=NO;
";
Jet OLEDB // etc. etc //
I usually update the data source path manually, but since I want to expand the project I am doing to multiple other tasks, this manual update procedure becomes tiresome (change 1705
in the file path to 1706
from a cell value).
A few reasons keep me from making the solution in VBA:
- Security warning from macro-enabled file.
- Users know Excel-sheets as
.xlsx
and may not recognize.xlm
. - Inheritance. My successor, who eventually needs to edit something in the sheet might not know VBA.
I have searched around with no success. Relevant links that unfortunately do not answer the question are linked below.
- support.office.com: Change the source data for a PivotTable (Standard click way of updating)
- Excel macro to change external data query connections - e.g. point from one database to another (VBA solution)
- Microsoft Excel Data Connections - Alter Connection String through VBA (VBA solution to alteration of connection string)