Sheets.PrintOut メソッド (Excel) | Microsoft Learn

この文章では、Microsoft ExcelのPrintOutメソッドについて説明しています。PrintOutメソッドは、オブジェクトを印刷するための構文で、オプションのパラメータとして、印刷開始ページ(From)、最終ページ(To)、部数(Copies)、印刷プレビュー(Preview)、アクティブプリンター(ActivePrinter)、ファイルへの印刷(PrintToFile)、部数の整理(Collate)、ファイル名(PrToFileName)、印刷範囲の無視(IgnorePrintAreas)があります。例として、アクティブシートの印刷や特定ページの印刷方法が示されています。

Excel VBAのPrintOutメソッドについて

Excel VBA(Visual Basic for Applications)を使用していると、文書の印刷を自動化したいというニーズがあるかもしれません。その際に便利なのが、PrintOutメソッドです。このメソッドを使うことで、指定した範囲や設定に基づいて文書を印刷することができます。この記事では、PrintOutメソッドの構文、パラメーター、使い方の例を説明します。

構文

expression.PrintOut(From, To, Copies, Preview, ActivePrinter, PrintToFile, Collate, PrToFileName, IgnorePrintAreas)

expressionSheetsオブジェクトを表す変数です。

パラメーター

名前 必須/オプション データ型 説明
From オプション Variant 印刷を始めるページの番号。省略した場合は、最初のページから印刷が始まります。
To オプション Variant 印刷する最後のページの番号。省略した場合は、最後のページまで印刷されます。
Copies オプション Variant 印刷する部数。省略した場合は、1部印刷されます。
Preview オプション Variant Trueの場合、印刷前にMicrosoft Excelが印刷プレビューを表示します。Falseの場合、直ちに印刷されます。
ActivePrinter オプション Variant アクティブなプリンターの名前を設定します。
PrintToFile オプション Variant Trueの場合、ファイルに印刷します。PrToFileNameが指定されていない場合、ユーザーが出力ファイルの名前を入力するよう促されます。
Collate オプション Variant Trueの場合、複数部を整理して印刷します。
PrToFileName オプション Variant PrintToFileTrueの場合、印刷するファイルの名前を指定します。
IgnorePrintAreas オプション Variant Trueの場合、印刷領域を無視し、全体を印刷します。

戻り値

このメソッドは、型Variantの値を返します。

注意事項

FromおよびToの説明における「ページ」は、印刷されたページを指し、シートやワークブックの全体のページを指すものではありません。

以下は、PrintOutメソッドの使用例です。

1. アクティブシートを印刷する

ActiveSheet.PrintOut

このコードは、現在選択されているシートを印刷します。

2. ページ2から3まで印刷する

Worksheets("sheet1").PrintOut From:=2, To:=3

このコードは、指定したシートのページ2からページ3までを印刷します。

3. ページ2から3までを3部印刷する

Worksheets("sheet1").PrintOut From:=2, To:=3, Copies:=3

このコードは、ページ2からページ3までを3部印刷します。

サポートとフィードバック

Office VBAやドキュメントに関する質問やフィードバックがある場合は、Office VBAサポートとフィードバックを参照してください。サポートやフィードバックの方法が案内されています。

Excel VBAのPrintOutメソッドを活用することで、大量の印刷作業を効率化し、業務の生産性を向上させることができます。ぜひ、実際の業務に役立ててみてください。

————-

Sheets.PrintOut method (Excel) | Microsoft Learn

Source link

The article describes the syntax and parameters for the PrintOut method in Microsoft Excel VBA, which is used to print an object, such as a worksheet. It details several optional parameters that control various aspects of the printing process:

  1. From: Indicates the starting page for printing; defaults to the first page if omitted.
  2. To: Specifies the last page to print; defaults to the last page if omitted.
  3. Copies: Sets the number of copies to print; defaults to one if omitted.
  4. Preview: If set to True, opens print preview before printing; if False or omitted, prints immediately.
  5. ActivePrinter: Allows specifying the active printer’s name.
  6. PrintToFile: If True, prints to a file instead of a printer; prompts for a filename if not specified.
  7. Collate: If True, collates multiple copies printed.
  8. PrToFileName: Specifies the output filename when printing to a file.
  9. IgnorePrintAreas: If True, ignores any print areas and prints the entire object.

The article provides examples of how to use the PrintOut method, such as printing the active sheet or specific page ranges with multiple copies. Additionally, it encourages users to seek guidance for any questions or feedback about Office VBA.

関連記事

コメント

この記事へのコメントはありません。