View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default For Each Type mismatch

If you want to test for that gracefully, instead of just
having things fail, you could try:

============
Option Explicit
Sub foo()
Dim S As Object
For Each S In Sheets
If S.Type < xlWorksheet Then
MsgBox "You've got a non-worksheet in your workbook"
Else
... your code ...
End If
Next S
End Sub
=======================


Here is another possible way to do that...

Sub foobar()
Dim WS As Worksheet
If Excel4MacroSheets.Count + Charts.Count Then
MsgBox "You've got one or more non-worksheets in your workbook"
End If
For Each WS In Worksheets
'... your code ...
Next
End Sub

Rick Rothstein (MVP - Excel