2015-04-20 35 views
0

我想按下ID爲「run-report」的按鈕問題是有兩個按鈕具有相同的ID,我想按第二個按鈕。如何按VBA Excel Internet Explorer的第二個按鈕

Set tags = ie.Document.GetElementsByTagname("input") 
For Each tagx 
In tags If tagx.Value = "Run report" 
Then tagx.Click 
End If 
Next 

這適用於第一個按鈕,但無法找到按第二個按鈕的方法。任何人有任何提示?

在此先感謝

+0

總是幫助,以顯示相關的HTML源... –

+0

的HTML是黯然登錄後,它在速度完成,而隨後的平臺啓動編碼。我不覺得我有權從頁面發佈代碼。可悲的是。 –

回答

1

這聽起來具有相同id,Web開發人員傾向於使用獨特的此信息,屬性,因爲它通常是對CSS和JavaScript的參考......你肯定不陌生兩個按鈕意思是一樣的Value

Set tags = ie.Document.GetElementsByTagname("input") 
meetFirst = False '<-- we didn't meet any first button with id = "myID" yet 
For Each tagx In tags 
    If tagx.id = "myID" 
     If meetFirst = False Then 
      meetFirst = True '<-- we met the first button 
     Else '<-- if we get here, we are dealing with the second "myID" button 
      tagx.Click 
      Exit For '<-- we can end the loop 
     End If 
    End If 
Next 

我已經使用tagx.id的例子中,堅持你的一句的:無論如何,你可以隨時通過添加到您的代碼,告訴你一個控制變量,如果它是第一個或第二個時間控制這樣的問題按鈕具有相同的ID,我想按第二個。您可以更改屬性檢查與任何你想要的(.Value.className等)

+0

工作就像我的魅力。謝謝!只需添加一個「然後」如果tagx.ID爲其他人誰願意使用它。非常感謝! –

+0

@NiklasAndersson如果它有效,請接受答案(它會告訴其他人有同樣的問題,這是解決方案) –

相關問題