正在努力寻找解决这个问题的方法。
从 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
最佳答案
你可以尝试这样的事情,大量使用 reusing Internet Explorer COM Automation Object识别一个 IE 实例,然后您正在寻找的特定网页处于事件状态。
改变strURL = "http://www.theage.com.au/"
至
"My Page Title - Windows Internet Explorer" as necessary
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
关于internet-explorer - 使用带有 Visual Basic 的 IE 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9719015/