您使用的是SendKeys
这是非常不可靠:)为什么不找到文本框的名称和搜索按钮,并直接与它进行交互,如下所示?
Sub Get_Data()
Dim ie As Object, objInputs As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "http://www.scramble.nl/military-database/usaf"
Do While ie.readystate <> 4: DoEvents: Loop
'~~> Get the ID of the textbox where you want to output
ie.Document.getElementById("serial").Value = "03-3114"
'~~> Here we try to identify the search button and click it
Set objInputs = ie.Document.getElementsByTagName("input")
For Each ele In objInputs
If ele.Name Like "sbm" Then
ele.Click
Exit For
End If
Next
End Sub
注意:了解我是怎么得到的名字serial
和sbm
,指略低于图像上面给出的解释。
下面的代码搜索键盘类型值03-3114并获取表中的数据。如果我想搜索单元格A1中已经存在的值,并在单元格范围(“B1:E1”)中从表格中为“代码,类型,CN,单元”刮取值,我该怎么办?
直接就把值从A1
代替硬编码值
ie.Document.getElementById("serial").Value = Sheets("Sheet1").Range("A1").Value
的要想从表中的值,确定通过右键单击该表的元素就可以在浏览器中点击“检查/检查元素(在Chrome中,它只是Inspect
)”,如下所示。
我可以给你的代码,但我希望你能自己做。如果你仍然坚持,那么用你试过的代码更新问题,然后我们会从那里拿到它。
有趣的阅读:html parsing of cricinfo scorecards
嗨,你好,你能解释一下从哪个表中,U闯民宅.. – HA560
@ HA560我的意思是tr.rowBoard表我有要导入从该表中的任何值成问题excel cell ... –