Hello
I am trying to run a code to access-query-to-excel-2010-to-create-a-graph-via-vba. However, anytime the editor displays ERROR 91.
I cannot see the final product.
Moreover, I need the query and the chart in the same worksheet and save the file.
'Any help is welcome.
This is the code:
I am trying to run a code to access-query-to-excel-2010-to-create-a-graph-via-vba. However, anytime the editor displays ERROR 91.

I cannot see the final product.
Moreover, I need the query and the chart in the same worksheet and save the file.
'Any help is welcome.
This is the code:
Code:
Option Compare Database
Option Explicit
Sub cmdTransfer_Click()
Dim sExcelWB As Workbook
Dim xl As Object ''Excel.Application
Dim wb As Object ''Excel.Workbook
Dim ws As Object ''Excel.Worksheet
Dim ch As Object ''Excel.Chart
Dim myRange As Object
Set xl = CreateObject("Excel.Application")
sExcelWB = "D:\testing\testchart.xlsx"
'This will overwrite any previous run of this query to this workbook
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_01", sExcelWB, True
Set wb = xl.Workbooks.Open(sExcelWB)
'Sheets are named with the Access query name
Set ws = wb.Sheets("qry_01")
Set ch = xl.Charts.Add
ch.ChartType = xlColumnClustered
xl.Visible = True
xl.UserControl = True
End Sub