次の方法で共有


プログラムによってドキュメントを印刷する

Microsoft Office Word ドキュメントの全体または一部を既定のプリンターに印刷できます。

適用対象: このトピックの情報は、Word のドキュメント レベルのプロジェクトおよび VSTO アドインのプロジェクトに適用されます。 詳細については、「Office アプリケーションおよびプロジェクトの種類別の使用可能な機能」を参照してください。

文書全体を印刷するには

  1. 文書全体を印刷するには、プロジェクトの PrintOut クラスの ThisDocument メソッドを呼び出します。 このコード例を使用するには、 ThisDocument クラスから実行します。

    object copies = "1";
    object pages = "";
    object range = Word.WdPrintOutRange.wdPrintAllDocument;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    object oTrue = true;
    object oFalse = false;
    
    this.PrintOut(ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue, 
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    

文書の現在のページを印刷するには

  1. プロジェクトの PrintOut クラスの ThisDocument メソッドを呼び出し、現在のページを一部印刷することを指定します。 このコード例を使用するには、 ThisDocument クラスから実行します。

    object copies = "1"; 
    object pages = "1"; 
    object range = Word.WdPrintOutRange.wdPrintCurrentPage; 
    object items = Word.WdPrintOutItem.wdPrintDocumentContent; 
    object pageType = Word.WdPrintOutPages.wdPrintAllPages; 
    object oTrue = true; 
    object oFalse = false; 
    
    this.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue, 
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
    

文書全体を印刷するには

  1. 印刷する PrintOut オブジェクトの Document メソッドを呼び出します。 アクティブ文書を印刷するコード例を次に示します。 この例を使用するには、プロジェクトの ThisAddIn クラスからコードを実行します。

    this.Application.ActiveDocument.PrintOut(true, false, Word.WdPrintOutRange.wdPrintAllDocument,
        Item: Word.WdPrintOutItem.wdPrintDocumentContent, Copies:"1", Pages:"", 
        PageType:Word.WdPrintOutPages.wdPrintAllPages, PrintToFile:false, Collate:true,
        ManualDuplexPrint:false);
    

文書の現在のページを印刷するには

  1. 印刷する PrintOut オブジェクトの Document メソッドを呼び出し、現在のページを一部印刷することを指定します。 アクティブ文書を印刷するコード例を次に示します。 この例を使用するには、プロジェクトの ThisAddIn クラスからコードを実行します。

    object copies = "1";
    object pages = "1";
    object range = Word.WdPrintOutRange.wdPrintCurrentPage;
    object items = Word.WdPrintOutItem.wdPrintDocumentContent;
    object pageType = Word.WdPrintOutPages.wdPrintAllPages;
    object oTrue = true;
    object oFalse = false;
    Word.Document document = this.Application.ActiveDocument;
    
    document.PrintOut(
        ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
        ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);