[英]What's the easiest way to list out the open windows in Excel VBA?
我知道我可以在谷歌上搜索,但我已经生疏了,以至于我不确定我应该搜索什么词。 在这里听取您的建议会有所帮助。
例子:
Sub Macro1()
'
' Macro1 Macro
'
'
Windows("FL_bounces.csv").Activate
Windows("auto_dealers_FL.csv").Activate
Windows("FL_bounces.csv").Activate
Windows("auto_dealers_FL.csv").Activate
End Sub
除了我不知道打开的窗户的名字的地方。
编辑#2:
Sub Macro1()
'
' Macro1 Macro
'
'
Dim wn, contacts, report As Excel.Window
Dim windows(1 To 100) As Excel.Window
Dim i As Integer
i = 1
For Each wn In Application.windows
windows(i) = wn
i = i + 1
Next wn
If IsEmailValid(windows(1).Cells(1, 1)) = True Then
report = windows(1)
contacts = windows(2)
Else
contacts = windows(1)
report = windows(2)
End If
End Sub
你觉得这个修改有什么问题?
这将在即时窗格中列出所有当前打开的窗口:
Sub ListWindows()
Dim wn As Excel.Window
For Each wn In Application.Windows
Debug.Print wn.Caption
Next wn
End Sub
或者,如果您想激活它们,如示例代码中所示
Sub ActivateWindows()
Dim wn As Excel.Window
For Each wn In Application.Windows
wn.Activate
MsgBox wn.Caption & " Window Activated"
Next wn
End Sub
试试 AutoIT。 您需要参考 AutoIT dll。 这是您可以下载 autoit dll http://www.autoitscript.com/site/autoit/ 的链接
AutoIt 中的变体数据类型本身支持窗口句柄 (HWND)。 窗口句柄是窗口每次创建时分配给窗口的特殊值。 当您有句柄时,您可以在任何使用标题/文本约定的函数调用中使用它代替标题参数。 使用窗口句柄的优点是,如果您打开了一个应用程序的多个副本 - 它们具有相同的标题/文本 - 您可以在使用句柄时唯一地标识它们。 当您为标题参数使用窗口句柄时,文本参数将被完全忽略。
WinGetHandle、WinList 和 GUICreate 等各种函数返回这些句柄。 需要注意的是,窗口句柄不属于数字或字符串——它是它自己的特殊类型。
Public Sub TestingAutoIT()
Dim autoItObj As AutoItX3
Set autoItObj = New AutoItX3
With autoItObj
.WinActivate ("A Window Name")
End With
Set autoItObj = Nothing
End Sub
今天我找到了VBA Express 发布的解决方案。 它将列出活动表上所有打开的窗口。
请注意,“一个窗口”不一定是用户通常想到的……有些窗口是许多窗口的集合,Windows 是这样看待它的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.