T
TimT
I'm trying to send the results of a query to Excel and I'm having trouble
with the code.
Sub AutomateExcel()
Dim strSQL As String
strSQL = "SELECT [qryName].* FROM [qryName]"
Dim xlApp As Variant
Dim xlBook As Variant
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Excel\Reports\ExcelReports.xls")
xlApp.sheets("Sheet1").Range("A1") = strSQL
xlBook.Close SaveChanges:=True
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
End Sub
with the code.
Sub AutomateExcel()
Dim strSQL As String
strSQL = "SELECT [qryName].* FROM [qryName]"
Dim xlApp As Variant
Dim xlBook As Variant
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Excel\Reports\ExcelReports.xls")
xlApp.sheets("Sheet1").Range("A1") = strSQL
xlBook.Close SaveChanges:=True
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing
End Sub