Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    May 2002
    Johannesburg, Gauteng, South Africa
    Thanked 0 Times in 0 Posts

    Embedded Charts (XL2002-SP1)

    Following on from where Hans last helped me to get a class module sorted out to easily automate the creation of embedded charts in a workbook, I'm now stuck on a seemingly trivial issue.

    When I create charts from code, I would like to name them appropriately for future reference. For example, each time I process a set of data, I would like to delete a certain chart (of known name!) if it exists, process the data and then recreate the chart with all it's appropriate new titles, legend, formatting, etc.

    I've tried some code at the time the chart is created, but it don't seem to be able to set the name property of a chart object.

    Selecting a chart and running the following code reads and prints the chart name to the immediate window, but fails on the name method.

    <font color=red>Sub RenameChart()

    Debug.Print ActiveChart.Name
    ActiveChart.Name = "Lab Results"

    End Sub</font color=red>

    The error message is "Method 'Name' of object '_Chart' failed."

    Maybe I should be using a ChartObject object or a Shape object or something to refer to the chart at a later stage ?

    Could someone please tell me what I'm missing here ?


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Embedded Charts (XL2002-SP1)

    Use the ChartObjects collection:

    ActiveSheet.ChartObjects(1).Name = "Lab Results"

    or use a ChartObject variable:

    Dim cht As ChartObject
    Set cht = ActiveSheet.ChartObjects.Add(100, 100, 300, 200)
    cht.Chart.ChartWizard Source:=Range("A1").CurrentRegion
    cht.Name = "Lab Results"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts