LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default Spreadsheet or Chart?

Edit: I'm posting this again as it did not appear in the NG although it made
it to the web pages on MSDN.

Hi Bob,

Whilst the worksheet constant will return the correct information the
xlChart does not.

This code illustrates that the Type value of a chart sheet is 3 not -4109 as
defined in the xlSheetType enum.

'------------------------
Sub x()

Dim objSheet As Object
Dim wksTemp As Worksheet
Dim chtTemp As Chart
Dim lngIndex As Long

Debug.Print "Constant Values"
Debug.Print "Worksheet", xlWorksheet, "Chart ", xlChart

Debug.Print "Using Activesheet object"
For lngIndex = 1 To ActiveWorkbook.Sheets.Count
ActiveWorkbook.Sheets(lngIndex).Activate
Debug.Print ActiveSheet.Name, ActiveSheet.Type,
TypeName(ActiveSheet)
Next

Debug.Print "Using Sheets Collection"
For Each objSheet In ActiveWorkbook.Sheets
Debug.Print objSheet.Name, objSheet.Type, TypeName(objSheet)
Next

Debug.Print "Using Worksheets collection"
For Each wksTemp In ActiveWorkbook.Worksheets
Debug.Print wksTemp.Name, wksTemp.Type, TypeName(wksTemp)
Next

Debug.Print "Using Charts collection"
For Each chtTemp In ActiveWorkbook.Charts
Debug.Print chtTemp.Name, chtTemp.Type, TypeName(chtTemp)
Next

End Sub
'------------------------

Debug output for a workbook with 3 worksheets and a chart sheet.
---------------------------------
Constant Values
Worksheet -4167 Chart -4109
Using Activesheet object
Chart1 3 Chart
Sheet1 -4167 Worksheet
Sheet2 -4167 Worksheet
Sheet3 -4167 Worksheet
Using Sheets Collection
Chart1 3 Chart
Sheet1 -4167 Worksheet
Sheet2 -4167 Worksheet
Sheet3 -4167 Worksheet
Using Worksheets collection
Sheet1 -4167 Worksheet
Sheet2 -4167 Worksheet
Sheet3 -4167 Worksheet
Using Charts collection
Chart1 3 Chart
---------------------------------

So maybe a test on the Typename is a more reliable method if you need to
know exactly the sheet type.

Cheers
Andy


--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"Bob Phillips" wrote in message
...
activesheet.type=xlworksheet 'xlchart

--
__________________________________
HTH

Bob

"Charlotte E." wrote in message
...
Is there any way to determine, from VBA, if the active sheet is a normal
spreadsheet or a chart/graph?




 
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
How do I display spreadsheet comments in a chart? GTYT Excel Discussion (Misc queries) 1 March 15th 09 05:16 PM
Floating a pie chart in my spreadsheet? Bill Excel Discussion (Misc queries) 0 September 9th 08 06:13 PM
converting chart to spreadsheet? excel chart Charts and Charting in Excel 1 July 2nd 06 01:56 AM
Pie chart not displaying % in spreadsheet MaryAnne@Maloney Charts and Charting in Excel 1 March 24th 06 08:07 PM
Get back from chart to spreadsheet nsv[_4_] Excel Programming 5 November 1st 05 01:48 PM


All times are GMT +1. The time now is 09:02 AM.

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"