ActiveSheet,ActiveWorkbook.ActiveSheet和Application.ActiveSheet的行为如何不同? [英] How do ActiveSheet, ActiveWorkbook.ActiveSheet and Application.ActiveSheet behave differently?
问题描述
我习惯总是像这样使用ActiveSheet
:ActiveWorkbook.ActiveSheet
.我最近偶然发现了此Microsoft页面,其中的代码包含ActiveSheet
而没有Application.ActiveSheet
属性.
I am in the habit of of always using ActiveSheet
like this: ActiveWorkbook.ActiveSheet
. I recently stumbled across this Microsoft page with code that includes ActiveSheet
without ActiveWorkbook
. The title of that page is Application.ActiveSheet
Property.
这三行代码之间有区别吗?
Is there a difference between these three lines of code?
ActiveSheet
ActiveWorkbook.ActiveSheet
Application.ActiveSheet
推荐答案
这些都引用相同的东西活动表,但是上下文可能与预期的不一样. ActiveSheet
的限制最少,它指的是当前"工作簿中的任何内容.
ActiveWorkbook.ActiveSheet
使其更加清晰.将其与运行代码的工作簿Thisworkbook
进行对比.
Application.ActiveSheet
指的是活动的工作簿或命名的工作簿/窗口.
如果您打开了多个工作簿,则最好始终明确要引用的对象.
These all refer to the same thing the active sheet, but the context may not be as expected. ActiveSheet
is the least restrictive and refers to whatever the 'current' Workbook may be.
ActiveWorkbook.ActiveSheet
just makes it a little more clear. Contrast this with Thisworkbook
which is the workbook where the code is running.
Application.ActiveSheet
refers to either the active workbook or the named workbook / window.
If you have more than one workbook open, it is always best to be explicit about the object you are referring to.
重要说明:ActiveSheet
单独使用并写在某些工作簿的代码模块ThisWorkbook
中时,与Application.ActiveSheet
和ActiveWorkbook.ActiveSheet
(始终相同)不同.在这种特殊情况下,即使ThisWorkbook
不是Excel应用程序的活动工作簿,ActiveSheet
仍引用ThisWorkbook.ActiveSheet
.
Important note: When alone and written in the code module ThisWorkbook
of some workbook, ActiveSheet
differs from both Application.ActiveSheet
and from ActiveWorkbook.ActiveSheet
(which are always the same). In this special case, ActiveSheet
refers to ThisWorkbook.ActiveSheet
even if ThisWorkbook
is not the active workbook of the Excel application.
这篇关于ActiveSheet,ActiveWorkbook.ActiveSheet和Application.ActiveSheet的行为如何不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!