2

正在努力寻找解决这个问题的方法。从 Visual Basic(更具体地说是 Excel 中的 VBA)我可以使用标题调用 Internet Explorer 窗口

AppActivate ("My Page Title - Windows Internet Explorer")

而且每次都很好用。

我可以打开一个新窗口并使用..向它发送一个网址。

Dim ie As Object
Set ie = New InternetExplorer
ie.Visible = True
ie.Navigate "http://websiteurl"

这也可以,但它每次都会打开一个新的浏览器,我希望它总是调用同一个窗口。

所以我可以ie每次都设置为相同的页面。所以而不是

Set ie = New InternetExplorer

它做了类似的事情

Set ie = ACTIVE InternetExplorer

(尽管这似乎不存在)。是否有某种设置方式ie与 相同AppActivate ("My Page Title - Internet Explorer")

谢谢

完整代码在这里:

Sub Find_Recordings()
Dim MyAppID, ReturnValue

AppActivate ("My Page Title - Windows Internet Explorer")

SendKeys ("^a")
Application.Wait (Now + TimeValue("0:00:01"))
SendKeys ("^c")
Application.Wait (Now + TimeValue("0:00:01"))

AppActivate ("Microsoft Excel")
Sheets("DataSearcher").Select
Range("K1").Select
ActiveSheet.PasteSpecial Format:="Text", Link:=False, DisplayAsIcon: = False

Range("A1").Select

Dim ie As Object
Set ie = New InternetExplorer
ie.Visible = True     ie.Navigate "http://wwwmyurl"

Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop

ie.Document.getElementById("searchdata1").Value = Range("J1")
ie.Document.getElementById("library").Value = "RECORDINGS"
ie.Document.searchform.Submit



End Sub
4

1 回答 1

1

您可以尝试这样的事情,重用 Internet Explorer COM 自动化对象来识别 IE 的实例,然后您正在寻找的特定网页处于活动状态。

更改
strURL = "http://www.theage.com.au/"

“我的页面标题 - Windows Internet Explorer”(根据需要)

VBA

Sub Test()
Dim ShellApp As Object
Dim ShellWindows As Object
Dim IEObject  As Object
Dim strURL As String
strURL = "http://www.theage.com.au/"
Set ShellApp = CreateObject("Shell.Application")
Set ShellWindows = ShellApp.Windows()
Dim i
For i = 0 To ShellWindows.Count - 1
    If InStr(ShellWindows.Item(i).FullName, "iexplore.exe") <> 0 Then
        If ShellWindows.Item(i).LocationURL = strURL Then
            Set IEObject = ShellWindows.Item(i)
            MsgBox "IE instance with " & strURL & " found"
            Exit For
        End If
    End If
Next
End Sub
于 2012-03-15T12:17:09.113 回答