2013-02-26 28 views
1

我面臨着一個關於我的VBA腳本的問題。 我的問題是,如何點擊與前一個ID相同的輸入按鈕的按鈕。唯一不同的是onclick值... 我的腳本適用於第一個ADD按鈕,但是當頁面加載時我不知道如何讓我的代碼點擊新的ADD按鈕(它具有相同的ID比前一個)。見下面我的代碼:VBA:輸入點擊getElementbyId的下一個類似的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...    

我有點卡住,任何幫助都會很難受。 有一個好的一天,感謝 在HTML文檔中

回答

0

id屬性都應該是獨一無二的,但你在兩個元素分配相同的值btnEdit。 dismabiguate他們,例如。通過附加按鈕的值屬性(btnEdit_ADD,btnEdit_EDIT)的內容。如果您需要表示按鈕是其中一種,請使用data--attribute(詳情請參閱here)。希望有所幫助,關心