Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Test to see if Sheet exists

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

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
Test if file exists Daniel Bonallack Excel Discussion (Misc queries) 2 May 4th 09 04:19 PM
Test if sheet exists create if not [email protected] Excel Programming 6 March 27th 06 09:51 PM
How to test if a DLL (library) exists ExcelMonkey Excel Programming 2 August 7th 05 08:14 PM
Test if Sheet Exists - Tom Ogilvy Steph[_3_] Excel Programming 8 September 23rd 04 04:37 AM
Test for Worksheet Exists bcmiller[_8_] Excel Programming 4 July 2nd 04 11:46 AM


All times are GMT +1. The time now is 12:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"