Share via


How to: Programmatically display documents in Print Preview

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

If your solution generates a report, you might want to display the report to the user in Print Preview mode.

Applies to: The information in this topic applies to document-level projects and VSTO Add-in projects for Word. For more information, see Features available by Office application and project type.

Procedures for document-level customizations

To display a document in Print Preview by calling the PrintPreview method

  1. Call the PrintPreview method of the Document class. To use this code example, run it from the ThisDocument class in your project.

    Me.PrintPreview()
    
    this.PrintPreview();
    

To display a document in Print Preview by setting the PrintPreview property

  1. Set the PrintPreview property of the Application object to true.

    Application.PrintPreview = True
    
    Application.PrintPreview = true;
    

Procedures for VSTO Add-ins

To display a document in Print Preview by calling the PrintPreview method

  1. Call the PrintPreview method of the Document that you want to preview. To use this code example, run it from the ThisAddIn class in your project.

    Me.Application.ActiveDocument.PrintPreview()
    
    this.Application.ActiveDocument.PrintPreview();
    

To display a document in Print Preview by setting the PrintPreview property

  1. Set the PrintPreview property of the Application object to true.

    Application.PrintPreview = True
    
    Application.PrintPreview = true;
    

See also