Exportar Query a Excel MS Access 2010
Intente exportar un Query a Excel pero me sale un error (Run Time error 3061), este es el código que use, VBA me muestra error en la línea en Negrita:
Public Sub ExportToExcel()
Dim XL As Excel.Application
Dim FileToRelease As Workbook
Dim qdKansas As QueryDef
Dim rsKansas As Recordset
'set up to the reference to the query to export
Set qdKansas = CurrentDb.QueryDefs("QueryFilterQuestions")
'set up the parameter
'execute the query
Set rsKansas = qdKansas.OpenRecordset()
'programmatically reference excel
Set XL = CreateObject("Excel.Application")
'set reference to the export workbook
Set FileToRelease = XL.Workbooks.Open("C:\Users\Henry\Documents\FileToRelease.xlsx")
'clear excel sheet
FileToRelease. Worksheets("Kansas"). Cells. ClearContents
'Use paste from recordset to put in the excel sheet
FileToRelease. Worksheets("Kansas").Cells(1, 1). CopyFromRecordset rsKansas
'save workbook
FileToRelease. Save
FileToRelease. Close
Set FileToRelease = Nothing
Set XL = Nothing
Set qdKansas = Nothing
End Sub