参考VBA中的窗口对象 [英] Reference to Window Object in VBA

查看:286
本文介绍了参考VBA中的窗口对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VBA中引用了一个Windows对象的问题。它会引发以下错误:错误5(无效的过程调用或参数)我找不到原因,因为我看不到编程错误。

I have a problem referencing a windows object in VBA. it throws the following error: "Error 5 (Invalid procedure call or argument). I cannot find the cause, because I see no programming error.

Public Sub TestWindowhandle()

Dim lResult As Long
Dim objShell, wins, winn
Dim IE_Count As Long, i As Long, This_PID As Long


On Error GoTo TestWindowhandle_Error

Set objShell = CreateObject("Shell.Application")
Set wins = objShell.Windows
IE_Count = wins.Count
For i = 0 To (IE_Count - 1)
   Set winn = wins.Item(i)
Next i

On Error GoTo 0
Exit Sub

TestWindowhandle_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in line " & Erl & " in procedure TestWindowhandle of Module Module1"
Stop
End Sub


推荐答案

与该界面有些奇怪,似乎只能使用控件变量的副本:

Something odd with that interface, it seems to only work with a copy of the control variable so:

Set winn = wins.Item(i + 0)

Set winn = wins.Item((i))

这篇关于参考VBA中的窗口对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆