VBA/Excel/Access/Word/Excel/Worksheet Hide — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 16:33, 26 мая 2010
Содержание
- 1 Hides the worksheet
- 2 Hiding and Unhiding Worksheets
- 3 To hide specific worksheet
- 4 To make a specific worksheet very hidden
- 5 To set the visible property to True on ALL sheets in workbook
- 6 To set the visible property to xlVeryHidden on ALL sheets in workbook.
- 7 To toggle between hidden and visible
- 8 To unhide a specific worksheet
- 9 Unhiding Every Worksheet in a Workbook.
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
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
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