Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
link excel charts to web pages and update charts automatically | Charts and Charting in Excel | |||
Help with naming | Excel Discussion (Misc queries) | |||
Naming charts on own sheet | Charts and Charting in Excel | |||
tab naming | Excel Worksheet Functions | |||
Tab naming | Excel Discussion (Misc queries) |