title: Export sql query results to excel using vba with headers
body: <p>I need to export a simple SQL query result to excel. I am able to get the results, however the headers are missing, how can I export the headers as well?</p>
  
  <p>This is what i have so far:</p>
  
  <pre><code>Sub Conn2SQL()
  
  Dim cnn1 As New ADODB.Connection
  Dim mrs As New ADODB.Recordset
  
  Set cnn1 = New ADODB.Connection
    cnn1.ConnectionString = "driver={SQL Server};server=MyDBServer;uid=MyuserID;pwd=mypassword;database=MyDB"
    cnn1.ConnectionTimeout = 30
    cnn1.Open  
  
  SQry = "use MyDB select * from TableName"
  
  mrs.Open SQry, cnn1
  
  Sheet2.Range("A2").CopyFromRecordset mrs
  
  mrs.Close
  cnn1.Close
  
  End Sub
  </code></pre>