我知道我一直可以在Google上进行搜索,但是直到我不确定应该搜索哪些术语时,我还是感到生锈。在这里听听您的建议会有所帮助。
示例:
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)。窗口句柄是窗口每次创建时分配给窗口的特殊值。有句柄时,可以在使用标题/文本约定的任何函数调用中使用它代替title参数。使用窗口句柄的好处是,如果您打开了一个应用程序的多个副本(它们具有相同的标题/文本),则可以在使用句柄时唯一地标识它们。当您将窗口句柄用作title参数时,text参数将被完全忽略。
各种函数,例如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
今天我找到了解决方案posted by VBA Express。它将在活动表上列出所有打开的窗口。
请注意,“窗口”不一定是用户通常想到的……某些窗口是许多窗口的集合,就像Windows看到它的方式。