【发布时间】:2020-03-26 17:30:46
【问题描述】:
这是我的第一个问题,我是 VBA 新手。
我试图运行一个宏来自动化 IE 上的一些程序。我的宏在不同的窗口上打开时效果很好,但是当我尝试在选项卡上运行相同的宏时它不起作用。似乎(也许)宏无法识别实际的选项卡。有人可以帮帮我吗?
Sub Test1()
Dim IE As Object
Dim doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
For intRow = 1 To 3
If intRow = 1 Then
With IE
.Visible = True
.navigate "https://gru.inpi.gov.br/pePI/jsp/patentes/PatenteSearchBasico.jsp"
Do While IE.Busy Or IE.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
Set doc = IE.document
IE.document.getElementById("principal").Children(4). _
getElementsByTagName("tbody")(0).getElementsByTagName("tr")(5). _
getElementsByTagName("td")(1).getElementsByTagName("font")(0). _
getElementsByTagName("input")(0).Value = "intRow"
Application.Wait DateAdd("s", 2, Now)
End With
Else
With IE
.Visible = True
.navigate "https://gru.inpi.gov.br/pePI/jsp/patentes/PatenteSearchBasico.jsp", 2048&
Do While IE.Busy Or IE.readyState <> 4
Application.Wait DateAdd("s", 1, Now)
Loop
.document.getElementById("principal").Children(4). _
getElementsByTagName("tbody")(0).getElementsByTagName("tr")(5). _
getElementsByTagName("td")(1).getElementsByTagName("font")(0). _
getElementsByTagName("input")(0).Value = "intRow"
Application.Wait DateAdd("s", 2, Now)
End With
End If
Next
End Sub
【问题讨论】:
-
您能否详细说明“不起作用”的含义。应该发生什么以及上面的代码中发生了什么?你有错误吗?
-
当然,我在假装浏览 trought 选项卡并从 excel 文件中填写输入内容。我设法通过新窗口做到这一点,但不是通过同一个选项卡。吕志的回答,效果很好。
标签: excel vba internet-explorer