この文章では、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)
expression
はSheets
オブジェクトを表す変数です。
パラメーター
名前 | 必須/オプション | データ型 | 説明 |
---|---|---|---|
From |
オプション | Variant | 印刷を始めるページの番号。省略した場合は、最初のページから印刷が始まります。 |
To |
オプション | Variant | 印刷する最後のページの番号。省略した場合は、最後のページまで印刷されます。 |
Copies |
オプション | Variant | 印刷する部数。省略した場合は、1部印刷されます。 |
Preview |
オプション | Variant | True の場合、印刷前にMicrosoft Excelが印刷プレビューを表示します。False の場合、直ちに印刷されます。 |
ActivePrinter |
オプション | Variant | アクティブなプリンターの名前を設定します。 |
PrintToFile |
オプション | Variant | True の場合、ファイルに印刷します。PrToFileName が指定されていない場合、ユーザーが出力ファイルの名前を入力するよう促されます。 |
Collate |
オプション | Variant | True の場合、複数部を整理して印刷します。 |
PrToFileName |
オプション | Variant | PrintToFile がTrue の場合、印刷するファイルの名前を指定します。 |
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:
- From: Indicates the starting page for printing; defaults to the first page if omitted.
- To: Specifies the last page to print; defaults to the last page if omitted.
- Copies: Sets the number of copies to print; defaults to one if omitted.
- Preview: If set to True, opens print preview before printing; if False or omitted, prints immediately.
- ActivePrinter: Allows specifying the active printer’s name.
- PrintToFile: If True, prints to a file instead of a printer; prompts for a filename if not specified.
- Collate: If True, collates multiple copies printed.
- PrToFileName: Specifies the output filename when printing to a file.
- 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.
コメント