VBA/Excel/Access/Word/Excel/Worksheet Hide

Материал из VB Эксперт
Версия от 12:47, 26 мая 2010; Admin (обсуждение | вклад) (1 версия)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

Hides the worksheet

 
Sub HideWorksheet(ws As Worksheet, bVeryHidden As Boolean)
    If bVeryHidden Then
        ws.Visible = xlSheetVeryHidden
    Else
        ws.Visible = xlSheetHidden
    End If
End Sub



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



To hide specific worksheet

 
Sub Hide_WS1()
    Worksheets(2).Visible = Hide  " you can use Hide or False
End Sub



To make a specific worksheet very hidden

 
Sub Hide_WS2()
    Worksheets(2).Visible = xlVeryHidden
End Sub



To set the visible property to True on ALL sheets in workbook

 
Sub Un_Hide_All()
    Dim sh As Worksheet
    For Each sh In Worksheets
        sh.Visible = True
    Next
End Sub



To set the visible property to xlVeryHidden on ALL sheets in workbook.

 
Sub xlVeryHidden_All_Sheets()
    On Error Resume Next
    Dim sh As Worksheet
    For Each sh In Worksheets
        sh.Visible = xlVeryHidden
    Next
End Sub



To toggle between hidden and visible

 
Sub Toggle_Hidden_Visible()
    Worksheets(2).Visible = Not Worksheets(2).Visible
End Sub



To unhide a specific worksheet

 
Sub UnHide_WS()
    Worksheets(2).Visible = True
End Sub



Unhiding Every Worksheet in a Workbook.

 
Sub UnhideAllWorksheets() 
    Dim ws As Worksheet 
    For Each ws In ThisWorkbook.Worksheets 
        ws.Visible = xlSheetVisible 
    Next ws 
    Set ws = Nothing 
End Sub