我遇到了关于我的 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...
我有点卡住了,任何帮助将不胜感激。祝你有美好的一天,谢谢