使用名称包含特定单词的 VBA 取消隐藏工作表名称

Unhide sheets names using VBA whose name contain specific word

使用下面的代码,我可以 select 所有包含单词 "ba" 的工作表,但是,如果那些 sheets/tabs 被隐藏,我不能,我收到 "Run-time errror '1004':" 警告。

关于如何使此代码与隐藏 sheet/tabs 一起工作的任何建议?所以它会显示所有 sheets/tabs 名称 "ba" 即使它被隐藏了?如果它们是隐藏的,我希望它们出现或 .Visible = True

Sub listray()
Dim ws As Worksheet, flg As Boolean
For Each ws In Sheets
If LCase(ws.Name) Like "*ba*" Then
    ws.Select Not flg
    flg = True
End If
Next
End Sub
End Sub

工作表必须可见才能被选中。

If LCase(ws.Name) Like "*ba*" Then
    ws.Visible = xlSheetVisible
    ws.Select Not flg
    flg = True
End If

您无需 Select 工作表即可 hide/unhide 它。这将在工作表中循环,只留下名称为 Like "*ba*"

的工作表可见
Sub listray()

Dim ws As Worksheet

Application.ScreenUpdating = False
    For Each ws In Sheets
        ws.Visible = LCase(ws.Name) Like "*ba*"
    Next
Application.ScreenUpdating = True

End Sub