SheetExists


Function SheetExists(sName As String, _
    Optional oWb As Workbook) As Boolean
    
    ‘Returns true if sheet exists in the specified workbook.
    ‘If no workbook supplied, the activeworkbook is used.
    
    If oWb Is Nothing Then
        Set oWb = ActiveWorkbook
    End If
    
    On Error Resume Next
        SheetExists = CBool(Not oWb.Sheets(sName) Is Nothing)
    On Error GoTo 0

End Function

Posted in Uncategorized

2 thoughts on “SheetExists

  1. SheetExists does not work, always returns False in VBA from Office 2003. It may work if the current worksheet perhaps?

    Also comment lines begin with L and therefore will not compile.

    Should start with ‘ character instead.

  2. Paste the code into a regular code module (not a sheet module), and change the curly single quotes into straight single quotes.

    Doesn’t it work now? It does for me.


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published. Required fields are marked *