Hi guys,
I'm having some troubles passing a query to an existing .xls.
Code:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryTest", dbOpenDynaset)
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Finanstemp.xls")
xlApp.Windows(1).Visible = True
xlBook.Sheets(1).Range("A1").CopyFromRecordset rst
xlBook.Close savechanges:=True
xlApp.Quit
Set rst = Nothing
Set dbs = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
It's driving me crazy, since I keep getting the same error even if I try other queries.
Any ideas? Thanks.
Forgot to mention that the code stops at:
Set rst = dbs.OpenRecordset("qryTest", dbOpenDynaset)
I'm having some troubles passing a query to an existing .xls.
Code:
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("qryTest", dbOpenDynaset)
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open("C:\Finanstemp.xls")
xlApp.Windows(1).Visible = True
xlBook.Sheets(1).Range("A1").CopyFromRecordset rst
xlBook.Close savechanges:=True
xlApp.Quit
Set rst = Nothing
Set dbs = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
It's driving me crazy, since I keep getting the same error even if I try other queries.
Any ideas? Thanks.
Forgot to mention that the code stops at:
Set rst = dbs.OpenRecordset("qryTest", dbOpenDynaset)