Export (0) Print
Expand All
Expand Minimize

Workbook.PrintOut Method

Prints the workbook.

Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel (in microsoft.office.tools.excel.dll)

public virtual void PrintOut (
	[OptionalAttribute] Object From,
	[OptionalAttribute] Object To,
	[OptionalAttribute] Object Copies,
	[OptionalAttribute] Object Preview,
	[OptionalAttribute] Object ActivePrinter,
	[OptionalAttribute] Object PrintToFile,
	[OptionalAttribute] Object Collate,
	[OptionalAttribute] Object PrToFileName
)

Parameters

From

The number of the page at which to start printing. If this argument is omitted, printing starts at the beginning.

To

The number of the last page to print. If this argument is omitted, printing ends with the last page.

Copies

The number of copies to print. If this argument is omitted, one copy is printed.

Preview

true to have Microsoft Office Excel invoke print preview before printing the object. false to print the object immediately.

ActivePrinter

Sets the name of the active printer.

PrintToFile

true to print to a file. If PrToFileName is not specified, Excel prompts the user to enter the name of the output file.

Collate

true to collate multiple copies.

PrToFileName

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 to overall pages in the sheet or workbook.

Optional Parameters

For information on optional parameters, see Understanding Optional Parameters in COM Interop.

The following code example uses the PrintOut method to print one copy of the first two printed pages of the current workbook to a printer.

private void WorkbookPrintOutPrinter()
{
    // Add a range value to make sure that the workbook prints.
    // An empty workbook will not be printed.
    Globals.Sheet1.Range["A1", "A5"].Value2 = 55;
    this.PrintOut(1, 2, 1, false, "HP17642", false, false, missing);
}

The following code example uses the PrintOut method to print one copy of the first two printed pages of the current workbook to a file named C:\MyData.xls.

private void WorkbookPrintOutFile()
{
    // Add a range value to make sure that the workbook prints.
    // An empty workbook will not be printed.
    Globals.Sheet1.Range["A1", "A5"].Value2 = 55;
    this.PrintOut(1, 2, 1, false, missing, true, false, 
        @"C:\MyData.xls");
}

Show:
© 2014 Microsoft