title: import sql data into excel using vba
body: <p>I'm trying to pull data from SQL table into excel. I've recorded a macro doing so using the data source tool.  However the amount of data I'm pulling generally crashes excel.  Is there a way to add a variable in my vba script to limit the data pulled from the sql table?  Essentially adding a where clause to a select statement in sql.</p>
  
  <p>Thanks!</p>
  
  <p>-Sean</p>
  
  <pre><code>With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
      "OLEDB;Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=10.22.30.215;Use Procedure for Prepare=1;Aut" _
      , _
      "o Translate=True;Packet Size=4096;Workstation ID="FakeName";Use Encryption for Data=False;Tag with column collation when possible=Fa" _
      , "lse;Initial Catalog=FakeCatelog"), Destination:=Range("$A$1")). _
      QueryTable
      .CommandType = xlCmdTable
      .CommandText = Array( _
      """FakeName""")
      .RowNumbers = False
      .FillAdjacentFormulas = False
      .PreserveFormatting = True
      .RefreshOnFileOpen = False
      .BackgroundQuery = True
      .RefreshStyle = xlInsertDeleteCells
      .SavePassword = False
      .SaveData = True
      .AdjustColumnWidth = True
      .RefreshPeriod = 0
      .PreserveColumnInfo = True
      .SourceConnectionFile = _
      "C:\UFakeFilePathodc"
      .ListObject.DisplayName = "FakeName"
      .Refresh BackgroundQuery:=False
  End With
  End Sub`
  </code></pre>