Full Version: Determine if sheet is in different workbook
UtterAccess Discussion Forums > Microsoft® Office > Microsoft Excel
bekibutton
I can use this code to determine if a sheet exists in the current workbook.

Can anyone point me in the right direction for modifying it so that it could look in a different workbook?

Thanks frown.gif

Becki
freakazeud
Hi,
try:

Function SheetExists(wb As Workbook, strSheetName As String) As Boolean
' returns TRUE if the sheet exists in wb
SheetExists = False
On Error Resume Next
SheetExists = Len(wb.Sheets(strSheetName).Name) > 0
On Error GoTo 0
End Function

Then you can use it this way:

If Not SheetExists(Workbooks("WorkbookName.xls"), "MySheetName") Then
MsgBox "MySheetName doesn't exist!"
Else
MsgBox "MySheetName exist!"
End If

Untested!
HTH
Good luck
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.