VBA:IE Automation:从Open IE Window中检索URL;运行时错误438

时间:2014-07-30 18:52:31

标签: vba internet-explorer

我已经检查了一些关于如何检查Internet Explorer窗口标题以检索URL的有用线程。 我有这个:

    Set objShell = CreateObject("Shell.Application")

    For Each wd In objShell.Windows

        If InStr(wd.document.Title, "College") = 1 Then
           Exit For
        End If
    Next wd

    Worksheets("BTS").Cells(2, 2).Value = wd.LocationURL

但我一直得到"运行时错误438:对象不支持属性或方法"在If InStr线上。我无法弄清楚为什么它会抛出这个错误。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:0)

一种方法:

Dim objShell, sTitle, wd 

Set objShell = CreateObject("Shell.Application")

For Each wd In objShell.Windows
    sTitle = ""
    On Error Resume Next
    sTitle = wd.document.Title
    On Error Goto 0
    If InStr(sTitle, "College") = 1 Then
       Exit For
    End If
Next wd

Worksheets("BTS").Cells(2, 2).Value = wd.LocationURL