Application.ActiveSheet 属性 (Excel)
返回一个对象,它表示活动工作簿中或指定的窗口或工作簿中的活动工作表(顶部工作表)。 如果没有活动的工作表,则返回 Nothing。
语法
expression.ActiveSheet
expression:表示 Application 对象的变量。
注解
如果不指定对象识别符,则此属性返回活动工作簿中的活动工作表。
如果某个工作簿出现在若干个窗口中,那么该工作簿的 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 支持和反馈,获取有关如何接收支持和提供反馈的指南。
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈