Test to see if Sheet exists

B

BillyRogers

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
 
M

Mike H

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top