Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Worksheet Type Question 1

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi, all:

I have a procedure that asks for the name and type of a worksheet when I run through the sheets object and I get err 438 "Object Doesn't support this property..."

Code:
Sub countsheets()
'For i = 1 To Sheets.Count
'    MsgBox Sheets(i).Name '& vbCrLf & Worksheets(i).Name & vbCrLf & Worksheets(i).Type
'Next
For Each sh In ActiveWorkbook.Sheets
    sh.Activate
    MsgBox ActiveSheet.Name & vbCrLf & ActiveSheet.Type
Next

End Sub

If I use Worksheets, it's fine for type, but does not count a chart, DLG or Macro. If I use the sh object, it counts them all but errs on the type for charts,DLG or Macro. (I was trying ActiveSheet @ the end to see if that made a difference.

I'm trying to find the Type because other code will do something w/the sheet dependent on type.

thanks,


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 

Hi,

Try this...
Code:
Sub countsheets()
    Dim sh As Object
    On Error Resume Next
    For Each sh In ActiveWorkbook.Sheets
        Debug.Print sh.Name
        Debug.Print sh.Type
        If Err.Number <> 0 Then
            Debug.Print Err.Description
            Err.Clear
        End If
        Debug.Print
    Next

End Sub

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Skip:

Once again you're my hero (why didn't I think of it?). This was the printout:

Code:
Dialog1
Object doesn't support this property or method

Macro1
 3 

Chart1
 3 

Sheet1
-4167 

Sheet2
-4167 

aaa
-4167

So, now I know the error is on the DLG sheet, so I can allow for it.

thanks again,



Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 


Just as I allowed for the error that occured in this code.

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top