在工作簿中打印一些隐藏的和一些未隐藏的工作表

时间:2015-03-23 16:12:08

标签: excel vba

我已经设置了一个按钮来打印工作簿中的一些工作表,但我想隐藏一些工作表但仍然打印它们。如何更改以下代码,以便打印隐藏和隐藏工作表的混合。

Private Sub PrintNew_Click()
If Sheets("New").Range("email").Value <> "email" And ActiveSheet.Name = "New" Then
Cancel = True
MsgBox "Email Address Needs to be Completed", vbInformation
If response = vbCancel Then Exit Sub
Application.EnableEvents = True
response = MsgBox("Do you really want to print?", vbOKCancel)
If response = vbCancel Then Exit Sub
Application.ScreenUpdating = False
Range("copy") = "Customer Copy"
Sheets("New").PrintOut copies:=1, Collate:=True
Sheets("Disclosure").PrintOut copies:=1, Collate:=True
Sheets("GAP").PrintOut copies:=1, Collate:=True
Sheets("TCF").PrintOut copies:=1, Collate:=True
Sheets("Legal").PrintOut copies:=1, Collate:=True
Range("copy") = "File Copy"
Sheets("New").PrintOut copies:=1, Collate:=True
Sheets("Disclosure").PrintOut copies:=1, Collate:=True
Sheets("GAP").PrintOut copies:=1, Collate:=True
Sheets("TCF").PrintOut copies:=1, Collate:=True
Sheets("Legal").PrintOut copies:=1, Collate:=True
Range("copy") = "Customer Copy"
End If
End Sub

我希望能够隐藏&#34;披露&#34;,&#34; GAP&#34;,&#34; TCF&#34; &安培; &#34;法定&#34;

提前感谢您的帮助 约翰戴维斯

1 个答案:

答案 0 :(得分:0)

要查找打印工作表列表的方法的用户,无论其可见性设置如何,请尝试以下操作:

注意:打印两份(第一份为Customer Copy,第二份为File Copy

Sub Wsh_Print()
Dim aWsh As Variant
Rem Array with name of all worksheets to be printed
aWsh = [{"New","Disclosure","GAP","TCF","Legal"}]
Dim Wsh As Worksheet, vWsh As Variant
Dim vxWshVisible As Variant, b As Byte
    Application.ScreenUpdating = False
    For b = 1 To 2
        For Each vWsh In aWsh
            Set Wsh = ThisWorkbook.Worksheets(vWsh)
            With Wsh
                .Range("copy") = Choose(b, "Customer Copy", "File Copy")
                vxWshVisible = .Visible                 'Record original worksheet visibility
                .Visible = xlSheetVisible               'Make worksheet visible
                .PrintOut IgnorePrintAreas:=False       'Print worksheet
                .Visible = vxWshVisible                 'Reset original worksheet visibility
                .Range("copy") = "Customer Copy"
    End With: Next: Next
    Application.ScreenUpdating = True
End Sub