Andy Pope. Again I appreciate your help.
I tested your suggestion within "With ch" in my code (below) and again I failed: "ERROR 424 and object is required" in line:
.Axes(xlValue, xlValue).MaximumScale = Chart 1.Range("Axis_max").Value
I think I don't know how to reference it.
Let me know about my project.
In Access I have a Form with 2 textboxes and one command button.
In txttask_plot, user types plot value (numeric)
In txttask_from, the user selects day1 (Date)
In txttask_to, the user selects day1 (Date)
The command button runs a code that works fine exporting the query and creating the Chart
This is my code in my command button:
Sub cmdTransfer_Click()
Dim sExcelWB As String
Dim xl As Object ''Excel.Application
Dim wb As Object ''Excel.Workbook
Dim ws As Object ''Excel.Worksheet
Dim ch As Object ''Excel.Chart
Set xl = CreateObject("excel.application")
'This is the Path to export query data and Chart
sExcelWB = "D:\testing2\" & Replace(Me.txttask_from, "/", "_") & " - " & Replace(Me.txttask_to, "/", "_") & " - " & Replace(Me.txttask_plot, "/", "_") & "_qry_task.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qry_task", sExcelWB, True
Set wb = xl.Workbooks.Open(sExcelWB)
Set ws = wb.Sheets("qry_task")
Set ch = ws.Shapes.AddChart.Chart
With ch
.ChartType = xlColumnClustered
.SeriesCollection(2).AxisGroup = 2
.SeriesCollection(2).ChartType = xlLineMarkers
.ChartGroups(1).GapWidth = 69
'Add Chart Title
.HasTitle = True
.ChartTitle.Text = "Plot" & ":" & Me.txttask_plot.Value & " " & Range("C1").Value & " " & vbCrLf & "Between" & " " & "(" & Me.txttask_from.Value & " - " & Me.txttask_to.Value & ")"
.Axes(xlValue).MajorGridlines.Delete
.Axes(xlCategory, xlPrimary).HasTitle = False
.Axes(xlValue, xlPrimary).HasTitle = False
.SetElement (msoElementLegendBottom)
End With
xl.Visible = True
xl.UserControl = True
End Sub
What I'm looking for is for VBA to execute the following:
Read range B2(to the last row) in the query minimum and maximum values to set values range (or escale?) in the primary vertical axis
Read range C2(to the last row) in the query minimum and maximum values to set values range (or escale?) in the secondary vertical axis
Therefore, any time I export a query to Excel VBA will set the minimum and maximum values in Primary and Secondary Axes values
I have been googling for the last 3 days
to find a solution with no success.
I really appreciate your help.
Cheers
Bookmarks