我用我要选择的工作表的名称制作了数组。我想隐藏的所有其他工作表。它需要通过动态。
列表说我的数组是 Sheets(Array("Sheet1", "sheet2")).Select 并且我有 4 张工作表如何隐藏不在数组中的所有其他工作表?
回答1
隐藏表格
Sheets
集合包括工作表、图表等。- https://stackoverflow.com/a/63085324 是工作表的类似解决方案。
Option Explicit
Sub HideSheets()
' Do NOT hide:
Dim Exceptions As Variant: Exceptions = Array("Sheet1", "Sheet2")
Dim sh As Object
For Each sh In ThisWorkbook.Sheets
If IsError(Application.Match(sh.Name, Exceptions, 0)) Then
On Error Resume Next ' when trying to hide last visible sheet
If Not sh.Visible = xlSheetHidden Then
sh.Visible = xlSheetHidden
End If
On Error GoTo 0
End If
Next sh
End Sub