Working With Worksheets

Instead of setting the range, you can set a print area for a worksheet with the PrintArea property. You use this property with the PageSetup object, a child object of the Worksheets collection object. You assign a range of cells as the print area, for example: ActiveSheet.PageSetup. PrintArea = "$A$2:$G$8". This code sets the range of cells in the print area to A2-G8. Even if cells outside that range contain data, Excel does not print them. The dollar signs in front of the row and column references indicates that you use absolute references to the cells you want to add to the range. See Chapter 11 for more information about absolute cell references.

When you use the PrintArea property to set the range of cells to print, you can omit the From and To parameters with the PrintOut method. If you want to clear the print area, you need to use the PrintArea property again and assign it a value of False or an empty string. Both of the following lines of code clear the print area:


ActiveSheet.PageSetup.PrintArea ActiveSheet.PageSetup.PrintArea


< Type ActiveSheet.PrintOut.

■ The Print Preview screen displays.

■ Alternately, you can click Close to cancel the print.

< Type ActiveSheet.PrintOut.

—0 Type ActivePrinter:= "HP DeskJet 894Cxi", replacing HP DeskJet 894Cxi with the name of the printer to use.

Note: You need to specify the name of a printer that is defined on your system.

■ Specify any additional optional parameter values for the Print method.

■ The Print Preview screen displays.

—Q Click Print to print the specified cells.

■ Alternately, you can click Close to cancel the print.

■ Excel prints the cells.

Was this article helpful?

0 0

Post a comment