Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

chart naming in vba

Status
Not open for further replies.

fezzer

Technical User
Mar 20, 2002
14
GB
Hi!

Little question: Does anyone know how to create and name a chart using vba? I can rename a chart but whenever i create a new one the chart name changes. Sooo has anyone worked out how to plot certain values from a table into a graph with a set name?

Thanks

Fez
 
Use the Chart.Name property. For example, after creating the new chart, you can set

ActiveChart.Name="MySet"

Does that help? If not, please provide more details around what you're trying to accomplish.



Rob
[flowerface]
 
Rob,

I've tried this and I get a failure:

Method 'Name' of object "_Chart" failed


The following code is just a recorded macro..
Code:
    Charts.Add
    
    ActiveChart.ChartType = xlPie
    ActiveChart.SetSourceData Source:=Sheets("Summary").Range("B5:C6"), PlotBy _
        :=xlColumns
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Summary"

    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "DTC"
    End With
    ActiveChart.ApplyDataLabels Type:=xlDataLabelsShowValue, LegendKey:=False, _
        HasLeaderLines:=True
    ActiveChart.Name = "Chart"

    ActiveSheet.Shapes(strTest).IncrementLeft 162#
    ActiveSheet.Shapes(strTest).IncrementTop -105.75
    ActiveSheet.Shapes(strTest).ScaleWidth 1.21, msoFalse, msoScaleFromTopLeft
    ActiveSheet.Shapes(strTest).ScaleHeight 1.3, msoFalse, msoScaleFromTopLeft

any thoughts?

 
Hi,

The problem occurs when the CHART is relocated from a Chart Sheet to an embedded ChartObject.

Try this...
Code:
    Charts.Add
    
    With ActiveChart
        .Name = "Chart"
        .ChartType = xlPie
        .SetSourceData Source:=Sheets("Sheet3").Range("B5:C6"), _
            PlotBy:=xlColumns
        .Location Where:=xlLocationAsObject, Name:="Sheet3"
    End With
    With ActiveSheet.ChartObjects(ActiveSheet.ChartObjects.Count).Chart
        .HasTitle = True
        .ChartTitle.Text = "DTC"
        .ApplyDataLabels Type:=xlDataLabelsShowValue, LegendKey:=False, _
            HasLeaderLines:=True
    End With
:)

Skip,
Skip@TheOfficeExperts.com
 
Thanks for that! I'll give it a go now
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top