Is there any way to have Excel 2007 connect to a table or view in SQL Server without having to maintain a separate “Data Connection File”? I was hoping the connection string could be embedded within the Excel document. I would like to pass this Excel document around without having to send the Data Connection File with it. The only way to do this is have the Data Connection file on a network file share with the correct permissions. This seems ridiculous, because the security is set to Windows Authentication.
We want to stay away from ODBC.
Yes, you can do this with VBA.
You can either do it with a built-in database query (querytable) or via ADO.
If you don’t have any (or much) programming experience (or experience with ADO), you’ll probably want to go the querytable route.
The easiest way to figure out the code for that is to start the macro recorder, select Data | Get External Data | New Database Query. Then select new datasource, SQL Server, and go from there.
When you’re done, stop the macro recorder and view the code. There is likely a lot of extra stuff in the generated code, but it should get you started.