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

But, according to the documentation in help, 3 is the wrong value. xlChart
is supposed to be equal to -4109, not 3. Three is the value associated with
xlExcel4MacroSheet.

Following is what help says:

XlSheetType Enumeration
Specifies the worksheet type.
Version Information
Version Added: Excel 2007

Name Value Description
xlChart -4109 Chart
xlDialogSheet -4116 Dialog sheet
xlExcel4IntlMacroSheet 4 Excel version 4 international macro sheet
xlExcel4MacroSheet 3 Excel version 4 macro sheet
xlWorksheet -4167 Worksheet

© 2006 Microsoft Corporation. All rights reserved.



"Barb Reinhardt" wrote in message
...
I ran this in Excel 2003 and didn't have an issue.

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

Sub CheckSheetType()

Debug.Print "NewChart1", ThisWorkbook.Sheets("NewChart1").Type
Debug.Print "NewChart", ThisWorkbook.Sheets("Newchart").Type
End Sub

Both came out Type = 3

When I tried it in Excel 2007 before saving the file, I got the same
thing.
Also no problem if the workbook was an .xlsm workbook.

I tweaked my code a bit to see what I'd get for other things.

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

End Sub

Sub CheckSheetType()

Debug.Print "NewChart1", ThisWorkbook.Sheets("NewChart1").Type
Debug.Print "NewChart", ThisWorkbook.Sheets("Newchart").Type
Debug.Print "Macrosheet", ThisWorkbook.Sheets("Macrosheet").Type
Debug.Print "SHeet1", ThisWorkbook.Sheets("Sheet1").Type
Debug.Print "Sheet2", ThisWorkbook.Sheets("Sheet2").Type
Debug.Print "Sheet3", ThisWorkbook.Sheets("SHeet3").Type
End Sub

I only got -4167 for the regular worksheets.
--
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"