If worksheet exists


Posted by Ken on September 07, 2000 11:50 PM

Is there a statement you can use in VBA to say if a worksheet exists do this.
The same with workbook exists.



Posted by Celia on September 08, 0100 2:33 AM

Ken
To check if a worksheet exists in the avtive workbook :-

Sub ShExist()
Dim ws As Worksheet, sExist As Boolean
For Each ws In Worksheets
If UCase("the worksheet name") = UCase(ws.Name) Then
sExist = True
Exit For
End If
Next
If sExist = True Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

To check whether a workbook exists :-

Sub WB_Exist()
If Dir("the full path and filename") <> "" Then
MsgBox "Yes"
Else
MsgBox "No"
End If
End Sub

Celia