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

时间:2015-11-20 15:32:00

标签: excel vba loops

我要做的是使用Excel VBA:

  1. 登录亚马逊卖家
  2. 打开工作簿
  3. 循环列以获取订单号
  4. 将其放入搜索框
  5. 点击搜索按钮
  6. 转到订单页面并提取数据
  7. 然后将提取的数据返回到指定的列中 另一个Excel工作簿
  8. 循环和订单号部分是我目前难以理解的。到目前为止,我已经找到了这么多代码:

    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,最有可能是   '我的变量。我基本上试图在循环中做一个循环,提取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
    

0 个答案:

没有答案