每个 XL 过程的 hWnd;每个过程都位于 Z 顺序的顶部
这会连续激活每个正在运行的 XL 进程:
Public Sub Test()
Dim varAry()
Dim iInstances As Long
Dim hWndDesk As Long
Dim hWndXL As Long
Dim x As Long
Dim var As Variant
On Error Resume Next
'---
hWndDesk = GetDesktopWindow
Do
iInstances = iInstances + 1
hWndXL = FindWindowEx(GetDesktopWindow, hWndXL, "XLMAIN", vbNullString)
If hWndXL <> 0 Then
ReDim Preserve varAry(iInstances)
'Get the next Excel window
varAry(iInstances) = hWndXL
Else
Exit Do
End If
Loop
'---
For x = 1 To UBound(varAry)
MsgBox varAry(x)
var = SwitchToThisWindow(hwnd:=varAry(x), BOOL:=False)
Next x
exit_Sub
End Sub
但是 GetObject() 不能连续应用于每个被激活的进程。我想使用这样的对象来计算每个进程下打开的工作簿的数量。
感谢您的帮助。
This successively activates every XL process that happens to be running:
Public Sub Test()
Dim varAry()
Dim iInstances As Long
Dim hWndDesk As Long
Dim hWndXL As Long
Dim x As Long
Dim var As Variant
On Error Resume Next
'---
hWndDesk = GetDesktopWindow
Do
iInstances = iInstances + 1
hWndXL = FindWindowEx(GetDesktopWindow, hWndXL, "XLMAIN", vbNullString)
If hWndXL <> 0 Then
ReDim Preserve varAry(iInstances)
'Get the next Excel window
varAry(iInstances) = hWndXL
Else
Exit Do
End If
Loop
'---
For x = 1 To UBound(varAry)
MsgBox varAry(x)
var = SwitchToThisWindow(hwnd:=varAry(x), BOOL:=False)
Next x
exit_Sub
End Sub
But a GetObject() can't be applied successively to each of the processes that are activated. I'd like to use such an object to count the number of workbooks that are open under each process.
Thank you for any assistance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面的代码将计算找到的“父”类的数量。
从历史上看,我一直使用 Pat 或 JK 的 API Spy(从 98 年左右开始)来获取关于如何获取窗口句柄的 VBA/6 友好视图(为您生成 vb 代码,但建议对其进行编辑)
pInvoke.net 是所有 Win32 API 的重要资源,例如 FindWindow 和 FindWindowEx 用于上面的例子。检查每个链接,因为它们是有关如何正确实现这些功能的大量示例。
The code below will calculate the number of "Parent" classes that are found.
Historically I've always used Pat or JK's API Spy (since '98 or so) to obtain a VBA/6 friendly view of how to get the window handle (generates vb code for you, would recommend editing it though)
pInvoke.net is a great resource for all Win32 API's such as FindWindow and FindWindowEx used in the example above. Check the links for each as they're are extensive examples on how to properly implement the functions.