[英]microsoft excel vba copying data from webpage
通过vba-我需要转到页面 ,然后选择选项“ Hawb / direct awb no”。 在“跟踪方式”下拉列表中,输入从excel复制到“数字”字段中的单元格,然后单击“提交”按钮。
我该怎么做? 我正在使用excel 10和IE10。我尝试了如下所示的各种命令,但未成功:(
ie.document.getElementById("ctl00_contentPlaceHolderRoot_cboTrackBy").Focus
ie.document.getElementById("ctl00_contentPlaceHolderRoot_cboTrackBy").Click
ie.document.getElementById("ctl00_contentPlaceHolderRoot_cboTrackBy").Value = "aw"
ie.document.getElementById("ctl00_contentPlaceHolderRoot_cboTrackBy").FireEvent ("onchange")
ie.document.getElementById("ctl00_contentPlaceHolderRoot_txtTrackBy").Value = b 'ctl00_contentPlaceHolderRoot_linkButtonSubmit
ie.document.getElementById("ctl00_contentPlaceHolderRoot_linkButtonSubmit")(0).Click
更新:
我遵循了罗恩的回答。 我想复制ron的代码完成处理后得到的表。 我使用了跟踪号-PEN91227308
我尝试了以下命令。 但是它复制的数据不是表格格式。 当我将其粘贴到Excel中时,整行显示在单个单元格上。 我如何像在网页上那样将数据转换为表格格式?
Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject
clipboard.PutInClipboard
clipboard.SetText Doc.getElementById("ctl00_contentPlaceHolderRoot_grdVwHistory").innerHTML
您尝试与之交互的元素包含在IFrame中。 源代码显示可以在以下位置找到IFrame
<iframe name="Shipment Tracking" width="100%" height="450" id="content_iframe" src="http://apps.dbschenkerusa.com/apps/Tracking/" frameborder="0" scrolling="auto">
在该网址上,您可以使用以下代码进行以下操作:1)选择正确的下拉框条目,2)在“数字”文本框中输入数字值,然后3)单击“提交”按钮
Sub test1()
' open IE, navigate to the website of interest and loop until fully loaded
Set ie = CreateObject("InternetExplorer.Application")
' my_url = "http://www.dbschenkerusa.com/log-us-en/start/eschenkerusa/shipmenttracking.html"
my_url = "http://apps.dbschenkerusa.com/apps/Tracking/"
With ie
.Visible = True
.navigate my_url
.Top = 50
.Left = 530
.Height = 400
.Width = 400
Do Until Not ie.Busy And ie.readyState = 4
DoEvents
Loop
End With
' Select the appropriate item from the drop-down box
ie.Document.getElementById("ctl00_contentPlaceHolderRoot_cboTrackBy").Value = "aw"
' Enter a value in the "Number" text box
ie.Document.getElementById("ctl00_contentPlaceHolderRoot_txtTrackBy").Value = "1234"
' Click the submit button
ie.Document.getElementById("ctl00_contentPlaceHolderRoot_linkButtonSubmit").Click
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.