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
        .PrintOut
    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
                .PrintOut
                .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
            .PrintOut
            .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
Worksheets.PrintOut

Print All Charts

'Print all Charts
Charts.PrintOut

Print Whole Workbook

'Print the active whole workbook
ActiveWorkbook.PrintOut
'Print this workbook which the VBA code in
ThisWorkbook.PrintOut

Print a Specific Sheet

'Print only "Sheet2"
Sheets("Sheet2").PrintOut

Print the Active Sheet

'only the activesheet
ActiveSheet.PrintOut

Print Selected Sheets

'Print all selected sheets
ActiveWindow.SelectedSheets.PrintOut

Print Selection

'Print only the selection
Selection.PrintOut

Print A Range

'Print range A1:C6
Range("A1:C6").PrintOut

Print preview

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

Comments

  1. Mark says

    Is there any way to read the response returned from the PrintPreview dialog screen. I’d like to know if the user printed or cancelled the printing. Appreciate any help. Thanks

  2. Prakash Kulkarni says

    Dear Sir / Ms.,

    I want to print A1, B1, C1 & D1 in one row. Then E1 in next row. Then F1 in next row, on a small sized paper. This way I want to print rows 1,2,3…etc. separately on separate sheets. How can I do that in Excel 2007?
    Thank you.

    Prakash Kulkarni

  3. Caspy says

    i would like to know how to print from sheet1, page 1 then sheet2, page 3 etc from a macro if its possable

  4. Pranab Chaturvedi says

    How to print data from only one worksheet to Text file and I need to insert the VB in another sheet.

  5. Mallesh says

    HI This is Mallesh,

    Could you please help me .

    Actually by using macros i have prepared progress cards. the problem is all printing in individual sheet.

    is there any possibility to print two reports in one sheet.

  6. says

    I see your blog needs some fresh & unique articles.
    Writing manually is time consuming, but there is solution for this.
    Just search for; Masquro’s strategies

  7. Eddie says

    I would like to know how to print Sheet 1 from multiple workbooks, rotate the page landscape, set the shaded are now in green to none but leaving the header the way it is in gray. The columns to prints start at A1 thru J to run for however many rows are in the worksheet. I print these files every so often but I can figure it out how to run a macro to do all of these at once.

Leave a Reply

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