Hi, I am relatively new to access, and have no real knowledge of vba. I have a query that is pulling data from a table. What I want is to run vba code when i open a specific form that will plot this data to excel for a specific range of values. Currently I have the following but I do not know how to specify the range eg cells A2:E2. Code below:
Private Sub Form_Load()
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 = "F:\TEST.xls"
''This will overwrite any previous run of this query to this workbook
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "CR", sExcelWB, True
Set wb = xl.Workbooks.Open(sExcelWB)
''Sheets are named with the Access query name
Set ws = wb.Sheets("CR")
Set myRange = ws.Range("A2
2")
Set ch = myRange.Charts.Add
xl.Visible = True
xl.UserControl = True
End Sub
As you can see I have attempted to specify the range but it doesnt work. when the code runs i am presented with a run time error message
any help would be fantastic
Thanks!
Private Sub Form_Load()
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 = "F:\TEST.xls"
''This will overwrite any previous run of this query to this workbook
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "CR", sExcelWB, True
Set wb = xl.Workbooks.Open(sExcelWB)
''Sheets are named with the Access query name
Set ws = wb.Sheets("CR")
Set myRange = ws.Range("A2

Set ch = myRange.Charts.Add
xl.Visible = True
xl.UserControl = True
End Sub
As you can see I have attempted to specify the range but it doesnt work. when the code runs i am presented with a run time error message
any help would be fantastic
Thanks!