Print Worksheets VBA

In Excel, when you click the Print button, Excel will not print hidden sheets, except use VBA. Here is a large examples of print Worksheets use Excel VBA, Before you read this tutorial, you may need to know the difference between Worksheets and Sheets.

PrintOut Syntax

expression.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, IgnorePrintAreas)

Print Worksheets on One Page

'Print Sheet1 exactly one page wide and tall
With Worksheets("Sheet1").PageSetup
    .Zoom = False
    .FitToPagesTall = 1
    .FitToPagesWide = 1
End With

Print Worksheets with Comments

Sub PrintWorksheetsWithComments()
    'Display all comments
    Application.DisplayCommentIndicator = xlCommentAndIndicator
    With ActiveSheet
        'As displayed on sheet
        .PageSetup.PrintComments = xlPrintInPlace
        'Print the active sheet
    End With
End Sub

Print Only Hidden Worksheets

Sub PrintOnlyHiddenWorksheets()
    Dim CurVis As Long
    Dim sh As Worksheet
    For Each sh In ActiveWorkbook.Worksheets
        With sh
            CurVis = .Visible
            If CurVis >= 0 Then
                .Visible = xlSheetVisible
                .Visible = CurVis
            End If
        End With
    Next sh
End Sub

Print Visible and Hidden Worksheets

Sub PrintHiddenAndVisibleWorksheets()
    Dim CurVis As Long
    Dim sh As Worksheet
    For Each sh In ActiveWorkbook.Worksheets
        With sh
            CurVis = .Visible
            .Visible = xlSheetVisible
            .Visible = CurVis
        End With
    Next sh
End Sub

Print Multiple Worksheets

'Print Sheet2 and Sheet3
Worksheets(Array("Sheet2", "Sheet3")).PrintOut

Print All Worksheets

'Print all worksheets

Print All Charts

'Print all Charts

Print Whole Workbook

'Print the active whole workbook
'Print this workbook which the VBA code in

Print a Specific Sheet

'Print only "Sheet2"

Print the Active Sheet

'only the activesheet

Print Selected Sheets

'Print all selected sheets

Print Selection

'Print only the selection

Print A Range

'Print range A1:C6

Print preview

'Active sheet print preview
ActiveSheet.PrintOut preview:=True

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. Darren Smith
    Darren Smith

    This is my attempt to choose then print a workbook sheet from a combo box. Please help to make it work.
    Private Sub Worksheet_Activate()
    Dim Sh As Worksheet
    For Each Sh In ThisWorkbook.Worksheets
    Me.cbSheet.AddItem Sh.Name

    Next Sh
    Dim i As Long, c As Long
    Dim SheetArray() As String

    With ActiveSheet.ComboBoxSOP
    For i = 0 To .ListCount – 1
    If .Selected(i) Then
    ReDim Preserve SheetArray(c)
    SheetArray(c) = .List(i)
    c = c + 1
    End If

    Next i

    End With


    End Sub

  2. Mohammed Mujeeb
    Mohammed Mujeeb

    I use this code the print worksheets ActiveWorkbook.Sheets(Array(1, 3, 4, 5, 6, 7, 8)).PrintOut Copies:=1, Collate:=True, _ IgnorePrintAreas:=False
    The file size is 12,632kb excel file has 6 images and one excel sheet of data. Please help me to find a way to reduce the file size

  3. Krishnan Muthuramaswamy
    Krishnan Muthuramaswamy

    ‘Print Sheet2 and Sheet3
    Worksheets(Array(“Sheet2”, “Sheet3”)).PrintOut
    Here I want to print certain range in sheet 2 and certain range in sheet 3 Is there any solution. I dont want whole sheet to get print