VBA Code


This property controls if page breaks (both automatic and manual) on the specified worksheet are displayed.

Application.PrintCommunication = False

This was added in Excel 2010
Means the printer is only contacted once

Displaying the Workbook in Print Preview


Displaying the Workbook in Page Break View

ActiveWindow.View = xlPageBreakPreview 
ActiveWindow.View = xlNormalView

PageSetup Object

Represents the page setup description. The PageSetup object contains all page setup attributes (left margin, bottom margin, paper size, and so on) as properties.

Using the PageSetup Object
Use the PageSetup property to return a PageSetup object. The following example sets the orientation to landscape mode and then prints the worksheet.

With Worksheets("Sheet1") 
    .PageSetup.Orientation = xlLandscape
End With

PrintPreview Method

Shows a preview of the object as it would look when printed.
This example displays Sheet1 in print preview.


PrintArea Property

Returns or sets the range to be printed, as a string using A1-style references in the language of the macro. Read/write String.
Set this property to False or to the empty string ("") to set the print area to the entire sheet.
This property applies only to worksheet pages.

This example sets the print area to cells A1:C5 on Sheet1.

Worksheets("Sheet1").PageSetup.PrintArea = "$A$1:$C$5" 

This example sets the print area to the current region on Sheet1. Note that you use the Address property to return an A1-style address.

ActiveSheet.PageSetup.PrintArea = ActiveCell.CurrentRegion.Address

PrintOut Method

expression.PrintOut( [ From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName ])
expression Required. An expression that returns an object in the Applies To list.

From - (Variant) The number of the page at which to start printing. If this argument is omitted, printing starts at the beginning.
To - (Variant) The number of the last page to print. If this argument is omitted, printing ends with the last page.
Copies (Variant) The number of copies to print. If this argument is omitted, one copy is printed.
Preview (Variant) True to have Microsoft Excel invoke print preview before printing the object. False (or omitted) to print the object immediately.
ActivePrinter (Variant) Sets the name of the active printer.
PrintToFile (Variant) True to print to a file. If PrToFileName is not specified, Microsoft Excel prompts the user to enter the name of the output file.
Collate (Variant) True to collate multiple copies.
PrToFileName (Variant) If PrintToFile is set to True, this argument specifies the name of the file you want to print to.


Pages in the descriptions of From and To refers to printed pages - not overall pages in the sheet or workbook.

This example prints the active sheet.


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext