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)?
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:
.xlsxand may not recognize
I have searched around with no success. Relevant links that unfortunately do not answer the question are linked below.
Long story short - NO. It is a giant security issue this way. If you find a way to do it, inform Microsoft immediately, they would be happy to fix it :) .
It would be definitely considered a bad practice by anyone who has ever earned a single dollar with SQL to read the data from a cell in Excel. I mean, the connection string is probably the most sensitive information that you possess. Even if you use VBA, make sure that the passwords are always written by the user in the cells (or through a form) and then erased. Not hardcoded in the code.
Microsoft can be considered bad by plenty of people, but they would never leave such a security hole in their products.