Skip to content

Latest commit

 

History

History
72 lines (51 loc) · 3.41 KB

how-to-programmatically-print-documents.md

File metadata and controls

72 lines (51 loc) · 3.41 KB
title description ms.date ms.topic dev_langs helpviewer_keywords author ms.author manager ms.subservice
Programmatically print documents
Learn how you can print an entire Microsoft Word document, or part of a document, to your default printer.
02/02/2017
how-to
VB
CSharp
Word [Office development in Visual Studio], printing documents
documents [Office development in Visual Studio], printing
John-Hart
johnhart
mijacobs
office-development

Programmatically print documents

You can print an entire Microsoft Office Word document, or part of a document, to your default printer.

[!INCLUDEappliesto_wdalldocapp]

Print a document that is part of a document-level customization

To print the entire document

  1. Call the xref:Microsoft.Office.Tools.Word.Document.PrintOut%2A method of the ThisDocument class in your project to print the entire document. To use this example, run the code from the ThisDocument class.

    :::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreWordAutomationCS/ThisDocument.cs" id="Snippet11":::

    :::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_VstcoreWordAutomationVB/ThisDocument.vb" id="Snippet11":::

To print the current page of the document

  1. Call the xref:Microsoft.Office.Tools.Word.Document.PrintOut%2A method of the ThisDocument class in your project and specify that one copy of the current page be printed. To use this example, run the code from the ThisDocument class.

    :::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreWordAutomationCS/ThisDocument.cs" id="Snippet12":::

    :::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_VstcoreWordAutomationVB/ThisDocument.vb" id="Snippet12":::

Print a document by using a VSTO Add-in

To print an entire document

  1. Call the xref:Microsoft.Office.Interop.Word._Document.PrintOut%2A method of the xref:Microsoft.Office.Interop.Word.Document object that you want to print. The following code example prints the active document. To use this example, run the code from the ThisAddIn class in your project.

    :::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreWordAutomationAddIn/ThisAddIn.cs" id="Snippet11":::

    :::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_VstcoreWordAutomationAddIn/ThisAddIn.vb" id="Snippet11":::

To print the current page of a document

  1. Call the xref:Microsoft.Office.Interop.Word._Document.PrintOut%2A method of the xref:Microsoft.Office.Interop.Word.Document object that you want to print, and specify that one copy of the current page be printed. The following code example prints the active document. To use this example, run the code from the ThisAddIn class in your project.

    :::code language="csharp" source="../vsto/codesnippet/CSharp/Trin_VstcoreWordAutomationAddIn/ThisAddIn.cs" id="Snippet12":::

    :::code language="vb" source="../vsto/codesnippet/VisualBasic/Trin_VstcoreWordAutomationAddIn/ThisAddIn.vb" id="Snippet12":::

Related content