Hi guys, I'm trying to simply export data in a recordset to an excel file, which I show in the code. Unfortunately, only a manual entry of the expiry file and path is possible. Here is my code:
Set rs= currentDB. Openrecordset("dynamic_query", opensnapshot)
Set objxl = CreateObject("Excel.Application")
Set objwkb = objxl.workbook.add
With objwkb.Worksheets(1)
.cells(1,1).copyfromrecordset rs
End with
objwkb.saveas filename:="h:\aaa\bb\output.xls"
Objxl.quit
Set objxl = nothing
I get an error 1004, meaning the saveas method could not be executed.
Instead of the .saveas file, the line below works, but that forces me to manually type the file and path:
Objwkb.close savechanges:=True
Set rs= currentDB. Openrecordset("dynamic_query", opensnapshot)
Set objxl = CreateObject("Excel.Application")
Set objwkb = objxl.workbook.add
With objwkb.Worksheets(1)
.cells(1,1).copyfromrecordset rs
End with
objwkb.saveas filename:="h:\aaa\bb\output.xls"
Objxl.quit
Set objxl = nothing
I get an error 1004, meaning the saveas method could not be executed.
Instead of the .saveas file, the line below works, but that forces me to manually type the file and path:
Objwkb.close savechanges:=True