By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,705 Members | 1,795 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,705 IT Pros & Developers. It's quick & easy.

Renaming an Excel Chart and referencing it by its name

100+
P: 119
I am creating a series of charts on a grid, 2 wide by four long. eg:

chart_1 chart_2
chart_3 chart_4
chart_5 chart_6
chart_7 chart_8

I want to have VBA code to replace an existing chart, in the same location, with a new chart. i.e. I want to be able to replace a chart in position i with a new chart, in position i.

The problem is, I'm not sure how to reference a chart by its location. The ChartObjects index does not refer to the location, only the order in which the chart was created. I had the idea of re-naming the chart by the location holder (chart_i), but I haven't been able to rename an embedded chart, nor reference it by its name.

Any ideas?
Oct 1 '08 #1
Share this Question
Share on Google+
1 Reply


100+
P: 119
It was this simple...It just had to be embedded on a worksheet, which obviously wasn't the case when I tried the first time.

Expand|Select|Wrap|Line Numbers
  1. ' Create a new chart at the desired location with the desired name
  2. Charts.Add
  3. ActiveChart.Location Where:=xlLocationAsObject, name:=ch.ChartWorksheetLocation
  4. ActiveChart.Parent.name = ch.ChartName
  5.  
Oct 2 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.