Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default naming charts

Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but found no
reference to this topic)... if naming is not possible how would i go about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default naming charts

Hi Tim,

Hold the shift key and then select the chart object. You should get
white handles at the corners instead of the usual black. You can now use
the Name box, next to the formula bar, to change the chart name.

With code,

Activechart.parent.name = "MyChart"

Cheers
Andy

Tim wrote:
Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but found no
reference to this topic)... if naming is not possible how would i go about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default naming charts

For embedded charts you are better off naming the container that
contains the chart. Using the GUI, hold down SHIFT and click on a
chart. You will see that circles framing the selected object (which
happens to be called a chartobject).

Next, check the contents of the Name Box (extreme left of the formula
bar. If all the charts have default names it will contain something
like Chart n where n is a number. Click in the Name Box, enter your
desired name and complete the naming process with the ENTER key.

You can now refer to the chart in VBA as {sheet-reference}.ChartObjects
({name-used-above}).Chart

To do the same in VBA when you create a chart, it would depend on how
you created the chart and what, if any, variable you've used in the
process. I always use a variable that refers to the chart. So, I
would use aChart.Parent.Name="My name for the chartobject"

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article , t_marsh@---take-
this-out-to-reply---atcentre.co.uk says...
Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but found no
reference to this topic)... if naming is not possible how would i go about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 167
Default naming charts

Tim

From my basis knowledge of charts in a sheet they are named based on how
they are created. The first chart you create on a sheet will be named Chart1
then Chart2, and so on.

You can determine the name of a chart by right clicking on a whitespace area
of the chart and selecting "Chart Window." Once you know the name of the
chart you can refer to it as follows:

This will select the first chart created on sheet1. For the second Chart
created you would change the 1 to a 2 and so on


Sheet1.ChartObjects(1).select


Mike


"Tim" wrote:

Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but found no
reference to this topic)... if naming is not possible how would i go about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default naming charts

superb! thanks for everybody's help here! its amazing i can have used
Excel for so long without ever realising something as apparently basic as
that!

"Andy Pope" wrote in message
...
Hi Tim,

Hold the shift key and then select the chart object. You should get
white handles at the corners instead of the usual black. You can now use
the Name box, next to the formula bar, to change the chart name.

With code,

Activechart.parent.name = "MyChart"

Cheers
Andy

Tim wrote:
Hi,

Could someone tell me if its possible to give a chart a name (with or
without VBA) so that it can be referenced in VBA (I've searched but

found no
reference to this topic)... if naming is not possible how would i go

about
referring to specific charts in vba (there are several charts on one
worksheet, so i cannot just refer to the worksheet).

Thanks people,

Tim



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default naming charts


Tushar,

I'm creating some charts and I want to name them as they are created for
further use on my macro, but i've been having trouble with it. I get an error
every time I try to rename the chart.
Here's my code :

Sub IPChart()
Charts.Add
With ActiveChart
.ChartType = xlColumnStacked
.SetSourceData Source:=Sheets("Recortadores").Range("B37:L94"),
PlotBy:=xlColumns
.Location xlLocationAsObject, name:="Recortadores"
End With

'To make sure there is a name, I always get "Recortadores Chart x"
MsgBox ActiveChart.name

ActiveChart.name = "HourChart"
End Sub


Sub prueba()
If ChartExists("Recortadores", "IPInfoChart") Then
MsgBox "ok"
End If
End Sub


I hope you can help me with this.
Greetings

--
Mariano


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default naming charts

As the chart is embedded you need to use

ActiveChart.parent.name = "HourChart"

Cheers
Andy

Mariano B. wrote:
Tushar,

I'm creating some charts and I want to name them as they are created for
further use on my macro, but i've been having trouble with it. I get an error
every time I try to rename the chart.
Here's my code :

Sub IPChart()
Charts.Add
With ActiveChart
.ChartType = xlColumnStacked
.SetSourceData Source:=Sheets("Recortadores").Range("B37:L94"),
PlotBy:=xlColumns
.Location xlLocationAsObject, name:="Recortadores"
End With

'To make sure there is a name, I always get "Recortadores Chart x"
MsgBox ActiveChart.name

ActiveChart.name = "HourChart"
End Sub


Sub prueba()
If ChartExists("Recortadores", "IPInfoChart") Then
MsgBox "ok"
End If
End Sub


I hope you can help me with this.
Greetings


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default naming charts

sorry, I forgot tu paste this code:


Function ChartExists(hoja As String, name As String) As Boolean
Dim C As ChartObject
On Error Resume Next
Set C = Sheets(hoja).ChartObjects(name)
If Err = 0 Then
ChartExists = True
Else
ChartExists = False
End If
End Function


--
Mariano


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default naming charts


Thanks Andy!
I hadn't considered that.

--
Mariano


"Andy Pope" wrote:

As the chart is embedded you need to use

ActiveChart.parent.name = "HourChart"

Cheers
Andy

Mariano B. wrote:
Tushar,

I'm creating some charts and I want to name them as they are created for
further use on my macro, but i've been having trouble with it. I get an error
every time I try to rename the chart.
Here's my code :

Sub IPChart()
Charts.Add
With ActiveChart
.ChartType = xlColumnStacked
.SetSourceData Source:=Sheets("Recortadores").Range("B37:L94"),
PlotBy:=xlColumns
.Location xlLocationAsObject, name:="Recortadores"
End With

'To make sure there is a name, I always get "Recortadores Chart x"
MsgBox ActiveChart.name

ActiveChart.name = "HourChart"
End Sub


Sub prueba()
If ChartExists("Recortadores", "IPInfoChart") Then
MsgBox "ok"
End If
End Sub


I hope you can help me with this.
Greetings


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
link excel charts to web pages and update charts automatically Signguy Charts and Charting in Excel 1 April 22nd 08 08:29 PM
Help with naming Mike Busch[_2_] Excel Discussion (Misc queries) 2 January 8th 08 12:04 AM
Naming charts on own sheet BoRed79 Charts and Charting in Excel 3 July 2nd 07 01:05 PM
tab naming [email protected] Excel Worksheet Functions 3 November 17th 06 07:24 PM
Tab naming Pedro AM Excel Discussion (Misc queries) 1 April 3rd 06 12:31 PM


All times are GMT +1. The time now is 11:40 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"