工作表和单元格的默认范围和范围是多少? [英] What is the default scope of worksheets and cells and range?

查看:35
本文介绍了工作表和单元格的默认范围和范围是多少?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您只输入 worksheets() 时,ActiveWorkbook 或 ThisWorkbook 的默认范围是什么?对于那些不知道这些区别的人来说,它们非常重要,尤其是在 Excel 2013 中,当您希望在切换到不同工作簿时运行宏时.

When you just type worksheets() what is the default scope ActiveWorkbook or ThisWorkbook? For those who do not know these distinctions they are extremely important especially in Excel 2013 when you want macros to run when you switch to different workbooks.

推荐答案

在标准模块中,未限定的 Worksheets() 将始终引用 ActiveWorkbook.在 ThisWorkbook 模块中,隐式限定符是 Me,它将引用包含的工作簿.

In a standard module an unqualified Worksheets() will always reference the ActiveWorkbook. In the ThisWorkbook module, the implicit qualifier is Me and that will reference the containing workbook.

同样,不合格的 Range()Cells()(或 Rows()/Columns()>) 在标准模块中将引用 ActiveSheet,但在工作表代码模块中,隐式限定符是 Me,并将引用相应的工作表.

Likewise, an unqualified Range() or Cells() (or Rows()/Columns()) in a standard module will reference the ActiveSheet, but in a sheet code module the implicit qualifier is Me, and will reference the corresponding worksheet.

Unqualified...       Where              Implicit Qualifier
--------------       --------------     -------------------
Worksheets(),        ThisWorkbook       Containing workbook (Me)
Sheets()             Any other module   Active workbook (via [_Global])

Range(), Cells(),    Sheet module       Containing sheet (Me)
Rows(), Columns(),   Any other module   Active sheet (via [_Global])
Names()

避免记住任何的简单方法是始终完全限定任何WorksheetsSheetsRangeCellsNames 引用.

The easy way to avoid having to remember any of this is to always fully qualify any Worksheets, Sheets, Range, Cells, or Names reference.

在该模块的代码隐藏中引用 ThisWorkbook 或在该模块的代码中引用 Sheet1 时,使用 Me 限定成员调用-在后面.

Qualify the member call with Me when referring to ThisWorkbook in that module's code-behind, or when referring to Sheet1 in that module's code-behind.

这篇关于工作表和单元格的默认范围和范围是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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