title: VBS: Pull SQL to Excel File
body: <p>I'm trying to create a simple VBS script that will allow a sql query to create an excel file.  All of my code below works, except it puts all 3 columns I am selecting into cell A1.  How can I get it to create a standard Excel output with the headers?</p>
  
  <pre><code>set objExcel = CreateObject("Excel.Application")
  objExcel.Application.DisplayAlerts = False
  set objWorkbook=objExcel.workbooks.add()
  
  Dim Connection
  Dim Recordset
  Dim SQL
  SQL = "SELECT PersonID, FirstName, LastName FROM [TestDB].[dbo].[Persons]"
  Set Connection = CreateObject("ADODB.Connection")
  Set Recordset = CreateObject("ADODB.Recordset")
  
  Connection.Open = "Provider=SQLOLEDB; Data Source=compname\SQL; Initial Catalog=DB; UID=usera; Integrated Security=SSPI"
  Recordset.Open SQL, Connection
  
  dim resultString, oRS
   Set oRS = Connection.Execute(SQL) 
  
  resultString = oRS.GetString
  
  Recordset.Close
  Set Recordset=nothing
  Connection.Close
  Set Connection=nothing
  
  Set objWorksheet = objExcel.Worksheets("Sheet1")
  objWorksheet.Name = "Third"
  objWorksheet.Activate
  objWorksheet.Cells(1, 1).Value = resultString
  
  objWorkbook.Saveas "C:\Users\usera\Desktop\Testing.xlsx"
  objWorkbook.Close
  objExcel.workbooks.close
  objExcel.quit
  set objExcel = nothing
  msgbox("Saved")
  </code></pre>