For Excel 2013
I have an req to display records from SQL DB into Excel table. Plan is to Embed SQL Query as Text file in Excel itself so that when user clicks a button, macro appends parameter to it and pass it as
ActiveWorkbook.Connections("Test1").OLEDBConnection.CommandText = query
'ActiveWorkbook.Connections("Test1").OLEDBConnection.Refresh
Q1) How can i read text content from embedded object into String variable to pass as stated above.
I have seem embedded object is stored in temp folder like C:\users\[username]\AppData\local\Temp\sql(2).txt.
Q1A) how do i read that file path through code avoiding hardwired.
Q2) Appreciate alternate suggestion of storing & reading query with below constrains.
my constraints are
- Cannot use Database to preserver query and make a call to it (stored proc..)
- Do not want to store query outside of Excel and read the query into Excel.
- Query is kind of dynamic in nature and not appropriate to hardwired entirely in cmdText connection properties via GUI for some reason.
Bookmarks