View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ken Loomis Ken Loomis is offline
external usenet poster
 
Posts: 143
Default Testing for existence of a worksheet in the active workbook

I need to add a new workseet to the active workbook, but I need test for its
existence before I do.

I used this:

If WorksheetExists("BuildQueries.xls", "Queries") Then
MsgBox ("sheet does exist")
Else
MsgBox ("sheet does NOT exist")
End If

with this function:

Function WorksheetExists(WBName As String, WSName As String) As Boolean

On Error Resume Next
WorksheetExists = _
(Workbooks(WBName).Worksheets(WSName).Name = WSName)
End Function


It works fine, but the name of the file may not always be
"BuildQueries.xls".

What do I need to use in place of "BuildQueries.xls" in the function call to
WorksheetExists to make it reference the active workbook?

Thanks,
Ken Loomis