Hiding and Unhiding Worksheets : Worksheet Hide « Excel « VBA / Excel / Access / Word






Hiding and Unhiding Worksheets

 
Sub HideWorksheet(sName As String, bVeryHidden As Boolean) 
    If WorksheetExists(ThisWorkbook, sName) Then 
        If bVeryHidden Then 
            ThisWorkbook.Worksheets(sName).Visible = xlSheetVeryHidden 
        Else 
            ThisWorkbook.Worksheets(sName).Visible = xlSheetHidden 
        End If 
    End If 
End Sub  
Function WorksheetExists(wb As Workbook, sName As String) As Boolean 
    Dim s As String 
    On Error GoTo bWorksheetExistsErr 

    s = wb.Worksheets(sName).Name 

    WorksheetExists = True 
    Exit Function 

bWorksheetExistsErr: 
    WorksheetExists = False 
End Function 

 








Related examples in the same category

1.To set the visible property to True on ALL sheets in workbook
2.To set the visible property to xlVeryHidden on ALL sheets in workbook.
3.To hide specific worksheet
4.To make a specific worksheet very hidden
5.To unhide a specific worksheet
6.To toggle between hidden and visible
7.Unhiding Every Worksheet in a Workbook.
8.Hides the worksheet