Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to find the type of Sheet in Excel.Workbook.sheets collection

Hi,

How can I find out what type of sheet ( Chart, Dialog, worksheet ) is
present in Excel workbook.Sheets collection. I need to perform two
different operations based on the type.

Thanks,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default How to find the type of Sheet in Excel.Workbook.sheets collection

Raj,

The obvious way is to check the sheets type property, but that deoesn't work
even though there are a whole set of type constants.

The previous post from Rob Bovey gives a safer method

'-------------------------

The Type property is only useful for distinguishing between regular
worksheets and the two types of XLM macro sheets. I don't really know why
they have constants in there for Charts and DialogSheets, but they don't
serve any purpose that I know of (the DialogSheet object doesn't even have a
Type property, as you've discovered).

Instead, you could use the TypeName function to return the string which
identifies the sheet type, then when you hit a worksheet use the Type
property to determine what type of sheet it is:

Sub ListSheetTypes()
Dim objSheet As Object
Dim szType As String
For Each objSheet In ActiveWorkbook.Sheets
szType = TypeName(objSheet)
If szType = "Worksheet" Then
Select Case objSheet.Type
Case xlWorksheet
Debug.Print szType
Case xlExcel4MacroSheet
Debug.Print "Excel4MacroSheet"
Case xlExcel4IntlMacroSheet
Debug.Print "Excel4IntlMacroSheet"
End Select
Else
Debug.Print szType
End If
Next objSheet
End Sub

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/


'--------------------------------------

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Raj" wrote in message
m...
Hi,

How can I find out what type of sheet ( Chart, Dialog, worksheet ) is
present in Excel workbook.Sheets collection. I need to perform two
different operations based on the type.

Thanks,



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 811
Default How to find the type of Sheet in Excel.Workbook.sheets collection

"Raj" wrote in message
m...
Hi,

How can I find out what type of sheet ( Chart, Dialog, worksheet ) is
present in Excel workbook.Sheets collection. I need to perform two
different operations based on the type.


Hi Raj,

Here's one way:

Dim objSheet As Object
For Each objSheet In ActiveWorkbook.Sheets
If TypeOf objSheet Is Excel.Worksheet Then
''' It's a worksheet.
ElseIf TypeOf objSheet Is Excel.Chart Then
''' It's a Chart sheet.
ElseIf TypeOf objSheet Is Excel.DialogSheet Then
''' It's a DialogSheet.
End If
Next objSheet

--
Rob Bovey, MCSE, MCSD, Excel MVP
Application Professionals
http://www.appspro.com/

* Please post all replies to this newsgroup *
* I delete all unsolicited e-mail responses *



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default How to find the type of Sheet in Excel.Workbook.sheets collection

Sub SheetTypes()
Dim sh As Object
For Each sh In ActiveWorkbook.Sheets
Debug.Print TypeName(sh)
Next
End Sub

--

Vasant


"Raj" wrote in message
m...
Hi,

How can I find out what type of sheet ( Chart, Dialog, worksheet ) is
present in Excel workbook.Sheets collection. I need to perform two
different operations based on the type.

Thanks,



Reply
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
setup help/excel wk/sheet to record museum library collection alaskakiwi New Users to Excel 1 January 26th 09 09:14 AM
Find exact match, same workbook, different sheets dmshurley Excel Discussion (Misc queries) 2 September 19th 07 03:02 AM
type in one sheet and appear on all sheets bigjim New Users to Excel 7 October 30th 06 04:55 PM
Find / Replace sheets vs workbook in VB Bony Pony Excel Worksheet Functions 0 December 8th 04 02:21 PM
Looking to save one sheet in a workbook of two sheets... Rob Bovey Excel Programming 2 August 29th 03 05:22 AM


All times are GMT +1. The time now is 03:43 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"