Application.ActiveSheet プロパティ (Excel)

作業中のブックまたは指定したウィンドウやブックにあるアクティブ シート (一番手前のシート) を表すオブジェクトを返します。 アクティブ シートが存在しないときは Nothing を返します。

構文

expression.ActiveSheet

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

注釈

対象となるオブジェクトを指定しない場合は、作業中のブックのアクティブ シートが返されます。

ブックを複数のウィンドウで表示している場合、異なるウィンドウでは ActiveSheet プロパティの値が異なることがあります。

例

次の使用例は、アクティブ シートの名前を表示します。

MsgBox "The name of the active sheet is " & ActiveSheet.Name

この例は、アクティブ シートの印刷プレビューを作成します。各ページの列 B の上にページ番号が表示されます。

Sub PrintSheets()

   'Set up your variables.
   Dim iRow As Integer, iRowL As Integer, iPage As Integer
   'Find the last row that contains data.
   iRowL = Cells(Rows.Count, 1).End(xlUp).Row
   
   'Define the print area as the range containing all the data in the first two columns of the current worksheet.
   ActiveSheet.PageSetup.PrintArea = Range("A1:B" & iRowL).Address
   
   'Select all the rows containing data.
   Rows(iRowL).Select
   
   'display the automatic page breaks
   ActiveSheet.DisplayAutomaticPageBreaks = True
   Range("B1").Value = "Page 1"
   
   'After each page break, go to the next cell in column B and write out the page number.
   For iPage = 1 To ActiveSheet.HPageBreaks.Count
      ActiveSheet.HPageBreaks(iPage) _
         .Location.Offset(0, 1).Value = "Page " & iPage + 1
   Next iPage
   
   'Show the print preview, and afterwards remove the page numbers from column B.
   ActiveSheet.PrintPreview
   Columns("B").ClearContents
   Range("A1").Select
End Sub

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

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。