View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
SixSigmaGuy[_4_] SixSigmaGuy[_4_] is offline
external usenet poster
 
Posts: 20
Default xlChart returning wrong value

I already solved my problem by re-writing my code; the reason for my post
was that I'm just wondering if I found a bug in VBA that should be reported.
Looking to see if others get the same results I did.


"Barb Reinhardt" wrote in message
...
Have you tried using something like this (for separate worksheets in the
workbook

Sub TestChart()
Dim myChart As Chart
For Each myChart In ThisWorkbook.Charts
Debug.Print myChart.Name
Next myChart

End Sub

If the Charts are embedded in the worksheets, it's a bit different.

Dim myChart as ChartObject
Dim WS as worksheet
for each WS in thisworkbook.worksheets
For each myChart in ws.chartobjects
debug.print mychart.name
next mychart
Next WS
--
HTH,
Barb Reinhardt



"SixSigmaGuy" wrote:

Hi,

I added a chart to my workbook using the Sheets.Add command, with the
"Type"
parameter set to xlChart.

But when I walk through the sheets in my workbook and check the "Type" of
each, it tells me that my chart is an xlExcel4MacroSheet instead of an
xlChart. According to help, xlChart has a value of -4109 and
xlExcel4MacroSheet has a value of 3. When I query the Type property of
the
new Chart I created, VBA says the value is 3, not -4109. Seems like
xlChart
is set to the wrong value; should it be 3 rather than -4109? Then again,
if
I add a new sheet using the value of 3 for the type parameter, I get a
new
worksheet, not a chart.

Anyone know what's going on? We were failing to process a lot of charts
because the wrong value was coming back. Following is a code snippet
showing my problem:

Sub AddNewChart()
Dim x As Variant
Set x = ThisWorkbook.Sheets.Add(Type:=xlChart)
x.Name = "NewChart"
End Sub

Sub CheckSheetType()
Debug.Print ThisWorkbook.Sheets("NewChart").Type
End Sub

Immediate Window shows "3"