0

我正在尝试制作一个 Excel 宏,将数据插入网络搜索表单,然后将结果复制到表格中。网络搜索表单实际上不是“表单”,而是一个空白表,所以我不能只更改表单的输入值,因为没有:

<td valign="top">
    <table border="0" cellspacing="0" cellpadding="2">
        <tr>
            <th class="navLabelText" align="left">Order:</th>
            <td>
                <input class="navEditField" id="opt_ordernumber_int" name="ordernumber" type="text" size="6" maxlength="6" />
            </td>
        </tr>
    </table>
</td>
<td width="10">&nbsp;</td>

HTML 只是继续使用更多相同类型的表单(我猜是用 Java 编码的,因为该站点是 .jsp)。有什么方法可以将值传递到空白表中?

这是我到目前为止所拥有的:

Sub featurecode()

Dim ie As Object
Dim doc As HTMLDocument
Dim links As IHTMLElementCollection
Dim link As HTMLAnchorElement
Dim i As Integer
Dim found As Boolean
Dim todaysURL As String

Dim objElement As Object
Dim objCollection As Object

Set ie = CreateObject("InternetExplorer.Application")

ie.Visible = True 'false
ie.navigate "https://website.com"
Application.StatusBar = "Loading Feature Codes"

Do Until ie.readyState = IE_READYSTATE.complete: DoEvents: Loop

Set doc = ie.document


' Find the input tag of the order form and submit button:
Set objCollection = ie.document.getElementsByTagName("input")

i = 0
While i < objCollection.Length
    If objCollection(i).Name = "ordernumber" Then

        ' Set text for search
        objCollection(i).Value = "655032"

    Else
        If objCollection(i).Type = "submit" And objCollection(i).Name = "Submit" Then

            ' "Search" button is found
            Set objElement = objCollection(i)
            objElement.Click

        End If
    End If
    i = i + 1
Wend

End Sub

我遇到问题的部分是:

If objCollection(i).Name = "ordernumber" Then

    ' Set text for search
    objCollection(i).Value = "655032"

通常你可以更改表单的 HTML 值,但是在这种情况下输入标签中没有 HTML 值,所以我很茫然。我的目标是简单地将订单号插入表单并点击提交按钮。不幸的是,我无法向您展示该网站,因为它是一个内部公司网站,但这里是相关信息的屏幕截图:screenshot

谢谢!

4

1 回答 1

-1

我在 VBA 中发现了一些元素,包括 INPUT,你必须首先关注元素:

    objCollection(i).Focus
    objCollection(i).Value = "655032"
于 2013-07-18T17:22:35.130 回答