title: How do I reference a Chart in an Excel VBA script Without The Chart Name
body: <p>I am creating an Excel VBA script to format and customize a chart.  I want to be able to use the script on different charts in different workbooks, so I can't have the chart name like "Chart 1" in the code.  I have seen ways to edit all the charts in a workbook, but I only want to edit the chart that I have clicked on in the workbook.</p>
  
  <p>The first part of my VBA script, that was created by saving keystrokes, is shown below: As you can see, "Chart 1" is hard coded with each block of code.  Is there a way that I can get away from using the chart name because I want to use this macro on different charts with different names. </p>
  
  <pre><code>Sub Format_Plot_Landscape()
  ActiveChart.ChartArea.Select
  With ActiveSheet.Shapes("Chart 1").Fill
      .Visible = msoTrue
      .ForeColor.ObjectThemeColor = msoThemeColorAccent1
      .ForeColor.TintAndShade = 0
      .ForeColor.Brightness = 0
      .Solid
  End With
  With ActiveSheet.Shapes("Chart 1").Fill
      .Visible = msoTrue
      .ForeColor.ObjectThemeColor = msoThemeColorBackground1
      .ForeColor.TintAndShade = 0
      .ForeColor.Brightness = 0
      .Transparency = 0
      .Solid
  End With
  ActiveChart.ChartArea.Select
  ActiveChart.PlotArea.Select
  ActiveSheet.Shapes("Chart 1").Line.Visible = msoFalse
  With Selection.Format.Fill
      .Visible = msoTrue
      .ForeColor.ObjectThemeColor = msoThemeColorBackground1
      .ForeColor.TintAndShade = 0
      .ForeColor.Brightness = 0
      .Solid
  End With
  .
  .
  .
  </code></pre>
  
  <p>It has been a long time since I created a VBA script in Excel, I used to do it a lot when I wanted to apply specific consistent formatting to different charts.  I dont remember the chart name being an issue.  In this case even when I try to apply the VBA script to the same chart that I recorded the keystrokes on, I get the error  "<em>The item with the specified name wasn't found</em>."  on the following line of code:</p>
  
  <pre><code>With ActiveSheet.Shapes("Chart 1").Fill
  </code></pre>
  
  <p>I didn't change the name of the chart.  I am running Office 2013 if that makes any difference.</p>