【问题标题】:ie.navigate2 document does not return second tabs documentie.navigate2 文档不返回第二个选项卡文档
【发布时间】:2017-05-01 05:53:58
【问题描述】:

尝试创建一个在 IE 中打开多个选项卡并填充文本区域的 vba excel 脚本。 像这样的:

   Sub tab_test()
link1 = "somelink1.com"
link2 = "somelink2.com"

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

IE.navigate link1
While IE.busy Or IE.readyState <> 4: DoEvents: Wend
Set IEdoc = IE.document
    For Each tag In IEdoc.getElementsByTagName("textarea")
        submit_comment = "Some content No1"
        tag.Value = submit_comment
    Next tag

IE.Navigate2 link2, 2048
While IE.busy Or IE.readyState <> 4: DoEvents: Wend
Set IEdoc2 = IE.document 'Here is the problem. It does not get the new document, but the first tab
    For Each tag In IEdoc2.getElementsByTagName("textarea")
        submit_comment = "Some content No2"
        tag.Value = submit_comment
    Next tag

End Sub

问题是当我尝试将 IEdoc2 设置为新文档时,它会将其设置为第一个。

【问题讨论】:

    标签: excel vba


    【解决方案1】:

    IE.Document 返回对活动文档的引用。您尚未将第二个选项卡中的文档设置为活动文档。

    您可能可以根据您的需要调整以下链接中的答案之一。 Accessing IE Tabs

    【讨论】:

    • 使用 shellwindows 选择第二个选项卡时,我得到一个“对象的方法文档失败”
    猜你喜欢
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-20
    • 1970-01-01
    相关资源
    最近更新 更多