View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
RB Smissaert RB Smissaert is offline
external usenet poster
 
Posts: 2,452
Default Determining if a Worksheet Exists

This is one way of doing it:

Function SheetExists(ByVal strSheetName As String) As Boolean

Dim x As Object

On Error Resume Next
Set x = ActiveWorkbook.Sheets(strSheetName)

If Err = 0 Then
SheetExists = True
Else
SheetExists = False
End If

End Function

Sub Test()

If SheetExists("TestSheet") Then
Msgbox "Sheet exists"
End if

End Sub


RBS


"Chaplain Doug" wrote in message
...
Excel 2003. In my VBA code I need to be able to determine if a particular
worksheet exists within a given workbook. For instance, how do I
determine
if WbMaster.Worksheets(SheetName) exists without getting an error if it
does
not? Thanks for the help.

--
Dr. Doug Pruiett
Good News Jail & Prison Ministry
www.goodnewsjail.org