Excel 循环一行并在特定过程中复制每个单元格
我要做的是使用Excel VBA:Excel 循环一行并在特定过程中复制每个单元格,excel,vba,loops,Excel,Vba,Loops,我要做的是使用Excel VBA: 登录亚马逊卖家 打开工作簿 循环一列以获取订单号 把它放在搜索框里 点击搜索按钮 转到订单页面并提取数据 然后将提取的数据返回到中的指定列中 另一份Excel工作簿 循环和订单号部分是我目前遇到的难题。到目前为止,我已经找到了这么多代码: Sub MyAmazonSeller() Dim MyHTML_Element As IHTMLElement Dim MyURL As String Dim oSignInLink As HTMLLinkElement
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,很可能是
“我的e变量。我基本上是在一个循环中做一个循环,提取5
'数据块,并将其粘贴回
'原始Excel表。问题出现在删除HTML时。我基本上
“试图在有几个级别的表格中获取文本是令人沮丧的
“我会永远爱你
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
使用HTMLDoc的
Set elems=HTMLDoc.getElementsByTagName(“td”)
对于元素中的每个e
如果e.innerText像“*1Z*”那么
范围(“D2”)。值=e.innerText
如果结束
下一个e
以
错误清除:
如果错误为0,则
呃,明白了
下一步继续
如果结束
端接头
谢谢@pnuts。这是一个漫长的一周,我与这个项目哈哈。不,你的格式更好。它更简明扼要。当我在这里发帖时,我只需要学会不要用复句来写谢谢@pnuts。这是一个漫长的一周,我与这个项目哈哈。不,你的格式更好。它更简明扼要。当我在这里发帖时,我只需要学会不要用复句来写