Udostępnij za pośrednictwem


WorkbookBase.PrintOut Method

Prints the workbook.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)

Syntax

'Declaration
Public Sub PrintOut ( _
    from As Object, _
    to As Object, _
    copies As Object, _
    preview As Object, _
    activePrinter As Object, _
    printToFile As Object, _
    collate As Object, _
    prToFileName As Object _
)
public void PrintOut(
    Object from,
    Object to,
    Object copies,
    Object preview,
    Object activePrinter,
    Object printToFile,
    Object collate,
    Object prToFileName
)

Parameters

  • from
    Type: System.Object
    The number of the page at which to start printing. If this argument is omitted, printing starts at the beginning.
  • to
    Type: System.Object
    The number of the last page to print. If this argument is omitted, printing ends with the last page.
  • copies
    Type: System.Object
    The number of copies to print. If this argument is omitted, one copy is printed.
  • preview
    Type: System.Object
    true to have Microsoft Office Excel invoke print preview before printing the object. false to print the object immediately.
  • activePrinter
    Type: System.Object
    Sets the name of the active printer.
  • printToFile
    Type: System.Object
    true to print to a file. If PrToFileName is not specified, Excel prompts the user to enter the name of the output file.
  • prToFileName
    Type: System.Object
    If PrintToFile is set to true, this argument specifies the name of the file you want to print to.

Remarks

"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 Optional Parameters in Office Solutions.

Examples

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 Sub 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
    Me.PrintOut(1, 2, 1, False, "HP17642", False, False)
End Sub
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 Sub 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
    Me.PrintOut(1, 2, 1, False, PrintToFile:=True, Collate:=False, _
        PrToFileName:="c:\MyData.xls")
End Sub
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");
}

.NET Framework Security

See Also

Reference

WorkbookBase Class

Microsoft.Office.Tools.Excel Namespace