在Visual Basic中使用IE浏览器

努力寻找解决scheme。 从Visual Basic(更具体地说,Excel中的VBA)我可以通过使用标题来调用Internet Explorer窗口

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

而且每次都很棒。

我可以打开一个新的窗口,并使用..发送一个url

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

而且,这也可以工作好但是它每次打开一个新的浏览器,我希望它总是调用相同的窗口。

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

 Set ie = New InternetExplorer 

它做了类似的事情

 Set ie = ACTIVE InternetExplorer 

(尽pipe这似乎并不存在)。 有一些设置方式, ieAppActivate ("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 

您可以尝试这样的事情,大量重复使用Internet Explorer COM自动化对象来识别IE的一个实例,然后find您正在查找的特定网页。

更改
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