ActiveSheet,ActiveWorkbook.ActiveSheet和Application.ActiveSheet的行为如何不同? [英] How do ActiveSheet, ActiveWorkbook.ActiveSheet and Application.ActiveSheet behave differently?

查看:404
本文介绍了ActiveSheet,ActiveWorkbook.ActiveSheet和Application.ActiveSheet的行为如何不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我习惯总是像这样使用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.ActiveSheetActiveWorkbook.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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆