internet-explorer - 使用带有 Visual Basic 的 IE 浏览器

标签 internet-explorer vba excel shdocvw

正在努力寻找解决这个问题的方法。
从 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

(尽管这似乎不存在)。
有没有办法设置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

最佳答案

你可以尝试这样的事情,大量使用 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/

相关文章:

vba - 声明关闭时编译错误

html - 我应该对 css.map 文件使用什么 rel 属性?

css - 滚动 div : Fill div, 中的表格,但防止不必要的水平滚动条

VBA/公式、工作表之间的映射

r - 导入 "special"个字符的 .csv 文件

vba - 非连续范围中的最后一行或单元格{不是工作表搜索}

internet-explorer - css3pie 是如何工作的?

html - IE兼容模式: strong tag= different width on different PCs?

excel - 如何使用模板回复所有人?

python - 如何通过xlwings包导入numpy? "ImportError: DLL load failed: The specified module could not be found."