title: Excel VBA - passing username & password to Web Query connection
body: <p>We have a web query on an Excel worksheet that goes to MoneyFacts (<a href="http://www.moneyfacts.co.uk" rel="nofollow">Moneyfacts website</a>) for the latest Bond &amp; ISA savings rates.</p>
  
  <p>The rates page requires a login by username and password before the rates page is shown (as it's a subscription site).</p>
  
  <p>Through trial and error and looking at the soruce of the login page, I was able to determin that I need to add these symbols to the connection:</p>
  
  <ul>
  <li>User Name: <strong>ctl00$body$txtUsername</strong></li>
  <li>Password: <strong>ctl00$body$txtPassword</strong></li>
  </ul>
  
  <p>so I changed thec onnection property of the datatable as below:</p>
  
  <pre><code>sheets("ISA 3Yr").range("A12").QueryTable.Connection="URL;http://analyser.moneyfacts.co.uk/savings/forms/frmDashboard.aspx?symbol=[""body_txtUsername""]”&amp;symbol=[""body_txtPassword""]”&amp;did=37&amp;module=2&amp;tocfilter=15&amp;view=2&amp;rerun=92680f6c-9fcc-4585-9b2a-aaf9b281cf88"
  </code></pre>
  
  <p>Now, when we click <em>refresh All</em> on the ribbon the first time, the dialogs are shown so we can enter the username and password. Each time we chose entered the data and the web query refreshed.</p>
  
  <p>But the next time, without asking for the login, it fails.</p>
  
  <p>How can we pass parameters to web queries properly ?</p>