title: How to use String as Source When Adding PowerQuery
body: <p>I'm trying to add the String <code>filename</code> as my source for adding a PowerQuery Connection, but for some reason Excel is not picking up on the string? Any ideas? If I add the full path as text it works well.</p>
  
  <p>My error is on the line <code>Csv.Document(File.Contents(filename)</code></p>
  
  <pre><code>Sub AddQuery()
  Dim newdate As Range
  Set newdate = Range("E2")
  Do Until Dir("D:\Users\rosenberggitty2\Dropbox\Personal\Done\Options\" &amp; newdate.Text &amp; ".csv") &lt;&gt; vbNullString
  newdate = newdate + 1
  Worksheets(1).Columns(5).AutoFit
  Loop
  
  Dim filename As String
  filename = "D:\Users\rosenberggitty2\Dropbox\Personal\Done\Options\" &amp; newdate.Text &amp; ".csv"
  
  Dim myConnection As WorkbookConnection
  Dim mFormula As String
  mFormula = _
  "let Source = Csv.Document(File.Contents(filename),null,""#(tab)"",null,1252) in Source"
  query1 = ActiveWorkbook.Queries.Add(newdate, mFormula)
  
  End Sub
  </code></pre>