[英]What is the difference between Application.Windows() and Excel.Windows() in Excel VBA?
基本上,我什么時候應該使用 Application.Windows(),什么時候應該使用 Excel.Windows()? 任何代碼示例都是特別可取的。
Excel
庫具有名為Windows
和Application
類。 然后Excel.Windows
是類Windows
的完全限定名稱。 類Application
具有名為Windows
屬性,它返回所有工作簿中的窗口集合。
因此,當您要引用類Windows
時可以使用Excel.Windows
,而要引用 windows 對象時將使用Application.Windows
屬性。 哈。
命名有問題。 類Windows
和屬性Windows
的名稱相同。 以下所有代碼示例使用Windows
屬性引用相同的窗口對象集合:
Dim eaw As Excel.Windows
Dim aw As Excel.Windows
Dim ew As Excel.Windows
Set eaw = Excel.Application.Windows
Set aw = Application.Windows
Set ew = Excel.Windows
代碼Set aw = Application.Windows
和Set ew = Excel.Windows
是相同的,因為許多返回最常見對象的屬性和方法可以在沒有Application
對象限定符的情況下使用。 可以在沒有 Application 對象限定符的情況下使用的屬性和方法被認為是global
,對於Windows
也是如此。
總之:
在聲明Excel.Windows
類型的變量時,使用完全限定名稱(例如Dim wnds As Excel.Windows
。
當提到窗口對象的集合時,您選擇哪種方式取決於您,以下所有內容都是等效的(返回相同的集合) Set eaw = Excel.Application.Windows
, Set aw = Application.Windows
, Set ew = Excel.Windows
. 注意:根據我的 Excel 2007 的對象瀏覽器,這個集合是read-only
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.