是否可以使用VBA确定Excel工作簿是否具有隐藏的工作表和/或隐藏的单元格?谢谢!

最佳答案

您可以遍历工作表,列和行,检查worksheet.visible和range.hidden属性。下面是一些快速而肮脏的代码,它将任何隐藏的元素输出到立即窗口。

Sub FindHidden()
    Dim wks As Worksheet
    Dim rng As Range

    For Each wks In ThisWorkbook.Worksheets
        If wks.Visible = xlSheetHidden Then
            Debug.Print "Worksheet: " & wks.Name & " is hidden."
        ElseIf wks.Visible = xlSheetVeryHidden Then
            Debug.Print "Worksheet: " & wks.Name & " is very hidden."
        End If

        For Each rng In wks.UsedRange.Rows
            If rng.Hidden = True Then
                Debug.Print "Worksheet: " & wks.Name & " Hidden Row: " & rng.Row
            End If
        Next rng

        For Each rng In wks.UsedRange.Columns
            If rng.Hidden = True Then
                Debug.Print "Worksheet: " & wks.Name & " Hidden Column: " & Left(Replace(rng.Address, "$", ""), 1)
            End If
        Next rng
    Next wks
End Sub

关于excel - 使用VBA在excel中查找隐藏的工作表(和隐藏的单元格),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7617000/

10-13 06:43