View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Tushar Mehta[_6_] Tushar Mehta[_6_] is offline
external usenet poster
 
Posts: 19
Default Chart into Userform Problem

As I explained, or tried to explain, the number that XL uses to refer
to an object has nothing to do with the name of the object.

Suppose you created 6 charts (or chartobjects) in succession. XL, by
default, would name them Chart 1 through Chart 6. So, you could refer
to them as .ChartObjects("Chart 1") through .ChartObjects("Chart 6").
In addition, you could also refer to them as .ChartObjects(1) through
....(6).

Now, suppose you delete the first five objects created. There will be
only one chartobject left on the worksheet and you would refer to it as
..ChartObjects(1). However, XL doesn't change the name of the object.
So, it would still be Chart 6.

You can always change the name of the chartobject with .ChartObjects
("Chart 6").Name="MyChartObject". After this change, the reference to
..ChartObjects("Chart 6") would be invalid and you would have to refer
to .ChartObjects("MyChartObject").

An easy 'trick' to change the name immediately after creating a new
chart is mySheet.ChartObjects(mySheet.ChartObjects.Count).N ame="myName"

--
Regards,

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

In article ,
says...
I double checked all Chart Names, even checked what the macor would be
called for each.

I have gone through every thing I can think of and I have tracked down the
porblem to the set currentchart when I changed the UpdateChart Macro

I included a msgbox to see what it was actually referencing. When I ran it
I found that for Chart 2 it was selecting Chart 6
So despite ChartNo =2 it was giving me Chart 6 in the MSgBox anf then Chart
6 would be appearing in the form.

Can anyone tell me why it would be giving me the error as this is totally
beyond me.



Private Sub UpdateChart()
currentchart = ""
testChartName = ""
Set currentchart = Sheets("Charts").ChartObjects(ChartNo).Chart
' CName = currentchart

Dim testChartName As String
testChartName = Sheets("Charts").ChartObjects(ChartNo).Name


MsgBox testChartName


currentchart.Parent.Width = 420
currentchart.Parent.Height = 190

' Save chart as GIF
Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
currentchart.Export Filename:=Fname, FilterName:="GIF"


' Show the chart
Image1.Picture = LoadPicture(Fname)
End Sub