title: Update queries in Excel using VBA
body: <p>I have a query (<strong>Query1</strong>) loaded into <strong>Excel</strong> by using a connection from <strong>Teradata</strong>. Normally when I want to update the query, I have to right click it and choose edit. </p>
  
  <p><a href="https://i.stack.imgur.com/X5OVU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X5OVU.png" alt="enter image description here"></a></p>
  
  <p>Once inside the <strong>Power Query Editor</strong>, I can open the <strong>Source</strong> and edit the <strong>SQL script</strong> inside to update the query. </p>
  
  <p><a href="https://i.stack.imgur.com/GDlVF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GDlVF.png" alt="enter image description here"></a></p>
  
  <p>The question is how can I edit this <strong>SQL script</strong> using <strong>VBA</strong>?</p>
  
  <p>Upon trying to use the <strong>Macro Recorder</strong>, I can only refresh the query using </p>
  
  <pre><code>ActiveWorkbook.Connections("Query - Query1").OLEDBConnection.Refresh
  </code></pre>
  
  <p>An attempt to edit the <strong>CommandText</strong> also failed. Here is the properties of the query.</p>
  
  <p><a href="https://i.stack.imgur.com/0VPRw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0VPRw.png" alt="enter image description here"></a></p>