打印除一页以外的所有页面,包括未隐藏页面

时间:2017-03-10 19:09:39

标签: excel vba excel-vba

我正在尝试打印包含隐藏工作表的Excel工作簿,我已使用下面的代码完成了该工作簿。我需要帮助排除打印表单“A”。所有表单“A”都填写了其他工作表信息。所以这只是浪费纸张被打印。

Sub PrintEachPage()
Dim ws As Worksheet
Dim CurSheet As Worksheet
    Set CurSheet = ActiveSheet
    For Each ws In ActiveWorkbook.Worksheets
    If ws.Visible = False Then
        If LCase(ws.Name) <> "a" Then
        ws.Visible = xlSheetVisible
        ws.PrintOut
        ws.Visible = xlSheetHidden
        Else
        ws.PrintOut
        End If
    End If
    Next ws
    CurSheet.Activate
End Sub

1 个答案:

答案 0 :(得分:0)

Visible不是布尔值,因此请使用If ws.Visible = xlSheetHidden Then

消除工作表&#34; a&#34;在第一次检查。然后取消隐藏隐藏的,打印它们,隐藏它们。如果可见,则只需打印。

 Sub PrintEachPage()
        Dim ws          As Worksheet
        Dim CurSheet    As Worksheet

        Set CurSheet = ActiveSheet

        For Each ws In ActiveWorkbook.Worksheets
            If LCase(ws.Name) <> "a" Then
                If ws.Visible = xlSheetHidden Then
                    ws.Visible = xlSheetVisible
                    ws.PrintOut
                    ws.Visible = xlSheetHidden
                Else
                    ws.PrintOut
                End If
            End If
        Next ws

        CurSheet.Activate
    End Sub