问题是这一行:
Set TrackID2 = oIE.document.getelementbyid("main-search-box")
基本上,我需要 VBA 来打开一个站点的两个实例(在 2 个选项卡中),找到搜索框并输入并提交一个字符串。
我打开了选项卡,但我找不到 VBA 将正确的字符串输入到 IE 实例中的第二个选项卡的方法。对,现在它打开了 2 个选项卡,但是将两个字符串都输入到第一个选项卡中并在那里搜索了两次,而第二个选项卡只打开了地址。
如何编辑代码以将 VBA 指向第二个选项卡,而不是第一个选项卡,就像现在一样?
提前谢谢你的帮助!
Sub TestIE()
Dim IE As Object
Dim TrackID As Object
Dim TrackID2 As Object
Dim address As String
address = "https://www.google.com/"
Const navOpenInNewTab = &H800
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
oIE.Navigate address
Do Until oIE.readystate = 4:
DoEvents: Loop
Set TrackID = oIE.document.getelementbyid("main-search-box")
TrackID.Value = ActiveSheet.Range("a1")
TrackID.form.submit
oIE.Navigate2 address, CLng(navOpenInNewTab)
Do Until oIE.readystate = 4:
DoEvents: Loop
Set TrackID2 = oIE.document.getelementbyid("main-search-box")
TrackID2.Value = ActiveSheet.Range("A2")
TrackID.form.submit
End Sub