In one of my Excel templates there is a preset chart that auto fills with data gained from an automated table.
That all works just fine. The part I am having trouble with is how to refer to that chart later in my code.
The best I can gather is using something like Main.xlBook.Charts(6), where 6 is the index of the chart in the xlBook.
Dim chart As Excel.Chart = CType(Main.xlBook.Charts(6), Excel.Chart)
chart.Axes(Excel.XlCategoryType.xlTimeScale).MinimumScale = Main.xLSheet1.Cells(2, 1).value / 86277
chart.Axes(Excel.XlCategoryType.xlTimeScale).MaximumScale = Main.xLSheet1.Cells(radios.Count + 1, 1).value / 86277
Using the code above, it breaks when I try to set the object. I don't want to make make the chart at runtime, because in most cases I do not need to edit the chart at all. The way I have it automated, it fills in correctly 95% of the time. I just need to be able to adjust the ranges the other 5%.
So is there a way to refer to a chart object in an xlbook that was not made at runtime?
ps, as a bonus second question, how would I change the axis with option strict turned on? (the way I have it currently is not option strict friendly)
Thanks guys as always
Update
Figured it out
Dim xlCharts As Excel.ChartObjects = CType(Main.xlSheet3.ChartObjects, Excel.ChartObjects)
Dim myChart As Excel.ChartObject = xlCharts.Item(5)
Dim chartPage As Excel.Chart = myChart.Chart
chartPage.Axes(Excel.XlAxisType.xlCategory).minimumscale = Main.xLSheet1.Cells(2, 1).value
chartPage.Axes(Excel.XlAxisType.xlCategory).maximumscale = Main.xLSheet1.Cells(radios.Count + 1, 1).value