View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Test to see if Sheet exists

Try this

Sub findme()
Dim wsSheet As Worksheet
On Error Resume Next
Set wsSheet = Sheets("Print_Recap")
On Error GoTo 0
If Not wsSheet Is Nothing Then
MsgBox "I'm Here"
Else
MsgBox "It's all gone dark"
End If
End Sub


Mike

"BillyRogers" wrote:

I have a program where I loop throught the worksheets in a folder and copy
the information from a worksheet called "Print_Recap".

There are a few workbooks in the folder that don't have this sheet and I
simply want to skip them and go on to the next workbook. The code i have
gives me an error message whenever it gets to a workbook without the
"Print_Recap" worksheet.

here's what I tried using but it doesn't work. I get error 9 subscript out
of range



Do While FNames < ""
Set mybook = Workbooks.Open(FNames)


Dim SheetExists As Boolean
SheetExists = False

SheetExists = CBool(Len(mybook.Sheets("Print_Recap").Name))
If SheetExists Then

'some code to run goes here

Else
SheetExists = False
End If

Loop

--
Billy Rogers

Dallas,TX

Currently Using SQL Server 2000, Office 2000 and Office 2003