PDA

View Full Version : Trying to create a chart without a Legend



scott56
04-29-2009, 09:22 PM
Hi,

I have a simple chart creation routine that works ok in 2003, I am now trying to get it working for 2007 and have struck a problem in that the HadLegend = False property does not seem to be working for the chart routine in 2007....basically it leaves the Legend on the chart.

Any suggestions would be appreciated

Set myChartDataLeftRange = mySourceRange.Offset(j, 1)
k = j
Do While mySourceRange.Offset(k, 1).Value <> "Total"
k = k + 1
Loop
Set myChartDataRightRange = mySourceRange.Offset(k - 1, myQuestionRange.Offset(i, 4).Value)
Set myChartDataRange = Range(myChartDataLeftRange, myChartDataRightRange)

Charts.Add
ActiveChart.ChartType = ConvertChartType(myQuestionRange.Offset(i, 2).Value)
ActiveChart.SetSourceData Source:=myChartDataRange, PlotBy:=xlColumns
ActiveChart.Location Where:=xlLocationAsNewSheet
ActiveChart.Name = myQuestionRange.Offset(i, 0).Value
ActiveChart.HasTitle = True
ActiveChart.ChartTitle.Text = myQuestionRange.Offset(i, 3).Value

ActiveChart.SeriesCollection(1).Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlNone
End With
ActiveChart.SeriesCollection(1).Points(1).Select
With Selection.Interior
.ColorIndex = myQuestionRange.Offset(i, 6).Value
.Pattern = xlSolid
End With
ActiveChart.SeriesCollection(1).Points(2).Select
With Selection.Interior
.ColorIndex = myQuestionRange.Offset(i, 7).Value
.Pattern = xlSolid
End With

ActiveChart.ChartArea.Select
ActiveChart.ApplyDataLabels AutoText:=True, LegendKey:=False, _
HasLeaderLines:=True, ShowSeriesName:=False, ShowCategoryName:=True, _
ShowValue:=True, ShowPercentage:=False, ShowBubbleSize:=False, Separator _
:="" & Chr(10) & ""

ActiveChart.SeriesCollection(1).DataLabels.Select
With Selection.Font
.FontStyle = "Bold"
.Size = 14
.Name = "Arial"
End With

ActiveChart.HasLegend = False
ActiveChart.PlotArea.Select
With Selection.Border
.Weight = xlThin
.LineStyle = xlNone
End With
Selection.Interior.ColorIndex = xlNone

ActiveChart.ChartArea.Select
If myQuestionRange.Offset(i, 0).Value = "Chart Q1" Then
Sheets(myQuestionRange.Offset(i, 0).Value).Move After:=Sheets("Source Data")
Else
Sheets(myQuestionRange.Offset(i, 0).Value).Move After:=Sheets(myQuestionRange.Offset(i - 1, 0).Value)
End If
ActiveWindow.Zoom = 102