循环遍历并复制每个单元格在特定的过程中

我必须做的是使用Excel VBA来:

  1. login亚马逊卖家
  2. 打开一个工作簿
  3. 通过列循环获取订单号
  4. 把它放在search框中
  5. 点击searchbutton
  6. 进入订单页面并提取数据
  7. 然后将提取的数据返回到另一个Excel工作簿中的指定列

循环和订单号码部分是我目前难住的。 到目前为止,我已经弄清了这么多的代码:

Sub MyAmazonSeller() Dim MyHTML_Element As IHTMLElement Dim MyURL As String Dim oSignInLink As HTMLLinkElement Dim oInputEmail As HTMLInputElement Dim oInputPassword As HTMLInputElement Dim oInputSigninButton As HTMLInputButtonElement 'InputSearchOrder will be the destination for order numbers taken from the workbook Dim InputSearchOrder As HTMLInputElement Dim InputSearchButton As HTMLInputButtonElement Dim IE As InternetExplorer Dim AAOrder As Workbook Dim AAws As Worksheet MyURL = "https://sellercentral.amazon.com/gp/homepage.html" Set IE = New InternetExplorer ' Open the browser and navigate. With IE .Silent = True .Navigate MyURL .Visible = True Do DoEvents Loop Until .ReadyState = READYSTATE_COMPLETE End With ' Get the html document. Set HTMLDoc = IE.Document ' See if you have the sign in link is because you are in the main ' page Set oSignInLink = HTMLDoc.getElementById("signin-button-container") If Not oSignInLink Is Nothing Then oSignInLink.Click Do DoEvents Loop Until IE.ReadyState = READYSTATE_COMPLETE End If ' Get the email field and the next button Set oInputEmail = HTMLDoc.getElementById("username") Set oInputPassword = HTMLDoc.getElementById("password") ' Click the button and wait oInputEmail.Value = "xxxxxx@xxxxxx.net" ' Get the password field and the sign in button Set oInputPassword = HTMLDoc.getElementById("password") Set oInputSigninButton = HTMLDoc.getElementById("sign-in-button") ' Click the button and wait oInputPassword.Value = "xxxxxxxx" oInputSigninButton.Click Do DoEvents Loop Until IE.ReadyState = READYSTATE_COMPLETE Application.Wait (Now + TimeValue("0:00:05")) Set AAOrder = Application.Workbooks.Open("Z:\Employee Folders\Employee\trackingnumber_sample_spreadsheet.xls") Set AAws = AAws.Worksheets("PrimeOrdersWithNoFulfillmentRe") Set InputSearchOrder = HTMLDoc.getElementById("sc-search-field") 'What I'm currently stuck on InputSearchOrder.Value = "001-7163923-7572632" Set InputSearchButton = HTMLDoc.getElementsByClassName("sc-search-button")(0) InputSearchButton.Click Do DoEvents Loop Until IE.ReadyState = READYSTATE_COMPLETE 

'能够添加这个片段,但是我得到了一个错误13,很可能与'我的evariables。 我基本上是试图在一个循环内做一个循环,提取5个数据块,并将它们粘贴回原来的Excel工作表的相应列中。 这个问题是在抓取HTML的时候出现的。 我基本上是“试图在有几个关卡的表格里面input文字,这让我感到沮丧。

 With HTMLDoc Set elems = HTMLDoc.getElementsByTagName("td") For Each e In elems If e.innerText Like "*1Z*" Then Range("D2").Value = e.innerText End If Next e End With Err_Clear: If Err <> 0 Then Err.Clear Resume Next End If End Sub