如何用VBA Excel Internet Explorer按第二个button

我试图按ID“运行报告”的问题是,有两个button具有相同的ID,我想按第二个button。

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

这适用于第一个button,但无法find一个方法来按第二个。 任何人有任何提示?

提前致谢

这听起来很奇怪的两个button具有相同的id ,Web开发人员倾向于使用此属性的独特信息,因为它通常是CSS和JavaScript的参考…你确定你不是指同一个Value ? 无论如何,你总是可以通过向你的代码添加一个控制variables来控制这个问题,这个variables告诉你是第一次还是第二次:

 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的例子,坚持你的句子button有相同的ID,我想按第二个 。 你可以改变属性来检查你想要的( .Value.className等)