I've programmically created a chart on the fly in Excel 2007. I'm running into an issue with the chart "deselecting" after being created. If I step through my code it all works with no issue, however if I let it run on its own the range selection at the end does not actually happen. Any ideas?
Sub FormatChart_Coverage(strChart As String)
Dim srs As series
ThisWorkbook.Sheets("Report").ChartObjects(strChart).Activate
ActiveChart.SetElement (msoElementLegendNone) ''Hide the legend
ActiveChart.SetElement (msoElementDataTableWithLegendKeys) ''Show the data table
For Each srs In ActiveChart.SeriesCollection
If srs.Name = "Total" Then
srs.AxisGroup = 2
srs.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlNone
End With
Selection.Interior.ColorIndex = xlNone
ElseIf srs.Name = "YTD Goal" Then
srs.ChartType = xlLineMarkers
srs.Select
With Selection
.MarkerStyle = -4115
.MarkerSize = 13
.MarkerBackgroundColorIndex = 3
.MarkerForegroundColorIndex = 3
End With
With Selection.Border
.LineStyle = xlNone
End With
End If
Next
ActiveChart.DataTable.Select
Selection.Font.Size = 8
ActiveChart.Axes(xlValue, xlSecondary).Select
Selection.MajorTickMark = xlNone
Selection.TickLabelPosition = xlNone
ThisWorkbook.Sheets("Report").ChartObjects(strChart).Select
Selection.OnAction = "'" & ThisWorkbook.Name & "'!Drill_CoverageForm"
ActiveChart.Deselect
ActiveSheet.Range("A1").Select
End Sub
Bookmarks