VBA Excel - 可以使用ActiveSheet的哪些方法/属性 [英] VBA Excel - What methods/attributes can I use with ActiveSheet

查看:2515
本文介绍了VBA Excel - 可以使用ActiveSheet的哪些方法/属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已查看 MSDN页面,并且还发现此问题有帮助,但我想知道如何ActiveSheet行为。是否像工作表对象?听起来它只是返回或引用一个Worksheet对象。使用正常的工作表方法和属性可以使用吗?

I have looked at the MSDN page, and also found this question helpful, but I would like to know exactly how ActiveSheet behaves. Is it like a Worksheet object? It sound like it just returns or references a Worksheet object. Do normal Worksheet methods and properties work with it?

我在其他来源复制的代码中使用了它,但是我想了解引擎盖下发生了什么。

I have used it in code I copied from other sources, but I would like to understand what is happening under the hood.

谢谢

奖金问题:如果我对sheet2有一个控制权,那么将活动表单设置为sheet1 userform,我可以在关闭userform时将其设置回sheet2吗?实质上,我可以在窗体激活时更改表格下方的表单来显示/操作数据?

Bonus question: If I have a control on sheet2, then set active sheet to sheet1 in a userform, can I then set it back to sheet2 when closing the userform? In essence, can I change the sheet below my form to display/manipulate data while the form is active?

推荐答案


它是否像Worksheet对象?

Is it like a Worksheet object?

ActiveSheet 是Like一个工作表对象,但它们不是相同。 ActiveSheet 可以是工作表图表表 MS Excel 4.0宏表 MS Excel 5.0对话框

Yes ActiveSheet is "Like" a worksheet object but they are not the same. ActiveSheet can be a "Worksheet", "Chart Sheet", "MS Excel 4.0 Macro Sheet" or "MS Excel 5.0 Dialog Sheet"

因此,应始终避免使用 Activesheet 与工作表一起工作。您可能不会使用您认为的工作表。

And hence one should always avoid using Activesheet while working with worksheets. You may not be working with the sheet you think you are.


正常的Worksheet方法和属性是否可以使用?

Do normal Worksheet methods and properties work with it?

如果 ActiveSheet 是一个工作表那么是的。例如,以下将适用于工作表,但不适用于 MS Excel 5.0对话框

If the ActiveSheet is a Worksheet then yes. For example, the below will work for a worksheet but not for "MS Excel 5.0 Dialog Sheet"

Debug.Print ActiveSheet.Range("A1").Address

关于你的奖金问题,是的可以将任何工作表设置为活动工作表,即将其放在前面,前提是工作表未隐藏。否则,您必须首先取消隐藏,然后激活它。

Regarding your bonus question, yes you can set any Worksheet to active sheet, i.e. bring it to the front, provided that the Worksheet is not hidden. Else you will have to unhide it first and then activate it.

要使工作表处于活动状态,您可以使用此

To make a worksheet active, you may use this

ThisWorkbook.Sheets("Sheet2").Activate

简而言之,避免使用 ActiveSheet 。使用对象来代替。 有兴趣阅读

In a nutshell, avoid using ActiveSheet. Work with objects instead. INTERESTING READ

这篇关于VBA Excel - 可以使用ActiveSheet的哪些方法/属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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