如何在VB脚本中使用已打开的IE? GetObject无法正常工作

时间:2017-12-15 06:53:06

标签: vbscript

下面是我用来打开新窗口的代码块。我尝试使用 GetObject 代替创建对象,如下所示。但是没有用。

Set IE = GetObject("","InternetExplorer.Application")

Dim IE
Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True
IE.navigate "https://msn.com"

Do While IE.ReadyState <> 4
    WScript.Sleep 1000
Loop

Set ElementCol = IE.Document.getElementsByTagName("a")

For Each Link In ElementCol
    If Link.innerHTML = "News" Then
    Link.Click
    WScript.Sleep(6000)
Exit For
End If
Next

IE.navigate "https://msn.com"

1 个答案:

答案 0 :(得分:0)

这使用了用于上网的资源管理器。

Set objShell = CreateObject("Shell.Application")
Do 
    Set AllWindows = objShell.Windows
    Count = 0
    For Each window in AllWindows
msgbox  window.locationname
'        window.refresh2 3
        Count = Count + 1
    Next
    If Count = 0 then Exit Do
    Wscript.sleep 5000
Loop