Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I display spreadsheet comments in a chart? | Excel Discussion (Misc queries) | |||
Floating a pie chart in my spreadsheet? | Excel Discussion (Misc queries) | |||
converting chart to spreadsheet? | Charts and Charting in Excel | |||
Pie chart not displaying % in spreadsheet | Charts and Charting in Excel | |||
Get back from chart to spreadsheet | Excel Programming |