Checking queries in Excel 2003

For the record, I am not a fan of Microsoft Excel. It’s not the application that annoys me so much as the way people use it. All too often, someone will write a quick and dirty script to pull data into Excel to solve a (supposedly) one-off issue. This spereadsheet is then copied and copied again until it becomes an unofficial part of some department’s workflow – undocumented and unsupported.

Then, years later and long after the original scripter has left, the data extract stops working and it falls to your local IT schmuck to figure out what is going on. And then the fun begins because it is not obvious where the query and database connection information are hidden.

After spending a bit of time with Google, I am now copying this information to here so that when I next need to check a query embedded in Excel, I can find the keystrokes a bit more quickly.

Cursor in the query results.
Alt+F11 to the VB editor
Ctrl+G to the immediate window
?ActiveCell.QueryTable.SQL
will give you the SQL of the query
?ActiveCell.QueryTable.Connect
will give you the connection details.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s