vba ActiveWorkbook 与 ActiveWindow

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24110359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-12 03:24:13  来源:igfitidea点击:

ActiveWorkbook vs ActiveWindow

excelvba

提问by Dhruvin Sukhadiya

What is the difference between ActiveWorkbookand ActiveWindow?

ActiveWorkbook和 和有ActiveWindow什么区别?

Sometimes I feel they are the same.

有时我觉得他们是一样的。

回答by Dhruvin Sukhadiya

  • Windows and Workbooks do have different properties/methods (although some are the same) so you can't always do with one what you might with the other.

  • ActiveWindowClose will not always close the workbook (for example if you have two or more windows open in the activeworkbook for example).

  • Also, if you use Windows(wbName).Activatethen you are also at the mercy of your windows settings ("Hide extensions for known file types") which will determine how your windows name appears (i.e. with or without the .xls(x)extension for example) which may cause the code to bug out.

  • Generally much better to avoid referring to the window unless you need to (e.g. to change the Height).

  • Windows 和工作簿确实具有不同的属性/方法(尽管有些是相同的),因此您不能总是用一种来做另一种。

  • ActiveWindowClose 不会总是关闭工作簿(例如,如果您在活动工作簿中打开了两个或多个窗口)。

  • 此外,如果您使用,Windows(wbName).Activate那么您也受制于您的 Windows 设置(“隐藏已知文件类型的扩展名”),这将决定您的 Windows 名称的显示方式(.xls(x)例如,有或没有扩展名),这可能会导致代码错误。

  • 通常最好避免引用窗口,除非您需要(例如更改高度)。