title: Extracting Excel Data Connection Command Text
body: <p>I have about 300 Excel files that have one or more "Microsoft Query" data connection that pulls data from a SQL server. I would like to take an inventory, then get rid of duplicates and old versions. </p>
  
  <p>In each query's data connection properties is a "Command Text" box that contains a Select statement that shows what tables and views it is accessing on the SQL server. I would like to pull this text out of all the files so I can evaluate them. </p>
  
  <p>I've used VBA to alter the Command Text so I didn't think it would be that difficult to do this. But my knowledge of VBA is pretty limited and despite a lot of research I haven't been able find the starting point: how to get the command text out into a text file. After that, should be able to figure out how to modify it to pull the info at once if there are multiple queries in the file. </p>
  
  <p>One thing I did discover is that it may not be possible to just export the Command Text alone. When I was trying to use export to ODC functionality, it looked like all the connection properties were included. That was fine but I never had any success in getting it to work.</p>
  
  <p><code>Application.ActiveWorkbook.ODBCConnection.SaveAsODC ("ODCFile")</code></p>
  
  <p>Thanks in advance</p>