1

我遇到了关于我的 VBA 脚本的问题。我的问题是,如何单击与前一个 ID 相同的输入按钮的按钮。唯一不同的是 onclick 值...我的脚本适用于第一个 ADD 按钮,但是当页面加载时,我不知道如何让我的代码单击新的 ADD 按钮(具有相同的 id比上一个)。请参阅下面的代码:

首次加载 HTML 页面:

<input id="btnEdit" class="button" onclick="openExpenseForm(1,'ExpenseCard.aspx?ExpenseFormID=c78f4ac6-63fc-4a47-a06a-a4eafe3ded08&ExpenseCardID=&Row=1&Action=New&Enabled=True');"
                        type="button" value="ADD" />

第二次加载 HTML 页面:

<input id="btnEdit" class="button" onclick="openExpenseForm(1,'ExpenseCard.aspx?ExpenseFormID=c78f4ac6-63fc-4a47-a06a-a4eafe3ded08&ExpenseCardID=&Row=1&Action=New&Enabled=True');"
                        type="button" value="EDIT" />
<input id="btnEdit" class="button" onclick="openExpenseForm(2,'ExpenseCard.aspx?ExpenseFormID=c78f4ac6-63fc-4a47-a06a-a4eafe3ded08&ExpenseCardID=&Row=1&Action=New&Enabled=True');"
                        type="button" value="ADD" />

VBA:

    Dim oIE As Object
Set oIE = CreateObject("InternetExplorer.Application")
    oIE.Visible = True
    URL = "http://netsteps/expense/ExpenseForm.aspx?Action=New&EmployeeID=" & ActiveSheet.Cells(1, 3)
    oIE.Navigate (URL)

AppActivate oIE

Dim objIE As SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll)
Dim htmlDoc As MSHTML.HTMLDocument ' html object lib
Dim htmlInput As MSHTML.HTMLInputElement
Dim htmlColl As MSHTML.IHTMLElementCollection
Set objIE = New SHDocVw.InternetExplorer

With objIE
With ActiveSheet

    Do While oIE.Busy: DoEvents: Loop
    Do While oIE.readyState <> 4: DoEvents: Loop


    oIE.document.getElementById("ctl00_Main_txtExpenseBusinessPurpose").Value = CStr(.Cells(2, 3))

    Do While (Not IsEmpty(.Cells(lin, 1)))

    Set htmlDoc = oIE.document
    Set htmlColl = htmlDoc.getElementsByTagName("input")

        For Each htmlInput In htmlColl
            If (htmlInput.Value = Trim("ADD") And Trim(htmlInput.Type) = "button") Then
                htmlInput.Click
            End If
        Next htmlInput

        Do While oIE.Busy: DoEvents: Loop
        Do While oIE.readyState <> 4: DoEvents: Loop
        ' Process 
        'End of all loops...            

我有点卡住了,任何帮助将不胜感激。祝你有美好的一天,谢谢

4

1 回答 1

0

idhtml 文档中的属性应该是唯一的,但是您btnEdit在两个元素中分配了相同的值。消除它们的歧义,例如。通过附加按钮的 value 属性 ( btnEdit_ADD, btnEdit_EDIT) 的内容。如果您需要表示按钮是一种按钮,请使用 -data-属性(有关详细信息,请参见此处)。希望有帮助,问候

于 2013-02-27T15:59:32.920 回答