title: Importing Access query output into Excel using VBA
body: <p>I am trying to get this code to work, but it doesn't seem to want to pull the string from the getopenfilename command, so I thought I would see if anybody has any ideas on how to reconfigure this code so that it will not treat the getopenfilename string as text and instead as a real path...</p>
  
  <pre><code>Sub DB_Import()
      Dim FilePath As Variant
  
      MsgBox ("Select the path and filename of the correct database")
      FilePath = Application.GetOpenFilename
  
      With ActiveSheet.ListObjects.Add(
          SourceType:=0, 
          Source:=Array( _
              "OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;Password="""";User ID=Admin; " &amp; _
              "DataSource=FilePath;Mode=Share Deny Write;Extended Properties=""""; " &amp; _
              "Jet OLEDB:System database="""";Jet OLEDB:Registry Path=""""; " &amp; _
              "Jet OLEDB:Database Password="""";Jet OLEDB:Engine Type=6;" &amp; _
              "Jet OLEDB:Database Locking Mode=0;Jet OLEDB:Global Partial Bulk Ops=2;" &amp; _
              "Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";" &amp; _
              "Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet " &amp; _
              "OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;" &amp; _
              "Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False;" &amp; _
              "Jet OLEDB:Bypass UserInfo Validation=False"), 
          Destination:=Range("$A$1")).QueryTable
  
          .CommandType = xlCmdTable
          .CommandText = Array("Query1")
          .RowNumbers = False
          .FillAdjacentFormulas = False
          .PreserveFormatting = True
          .RefreshOnFileOpen = False
          .BackgroundQuery = True
          .RefreshStyle = xlInsertDeleteCells
          .SavePassword = False
          .SaveData = True
          .AdjustColumnWidth = True
          .RefreshPeriod = 0
          .PreserveColumnInfo = True
          .SourceDataFile = FilePath
          .ListObject.DisplayName = "Table_ExternalData_1"
  
          .Refresh BackgroundQuery:=False
      End With
  End Sub
  </code></pre>