单击带有VBA的IE链接

时间:2014-08-19 11:47:03

标签: vba internet-explorer excel-vba excel

我正在尝试使用VBA点击网页上的链接,但由于某种原因我无法让它工作。

IE源代码:

<a class="WhiteboardLink" title="Hazards/Safe Acts" href="javascript:LinkTo('/Whiteboard.aspx?page=HomePage_OBS','Hazards/Safe Acts')" align="center"><img title="Hazards/Safe Acts" border="0" alt="Hazards/Safe Acts" src="/Images/Whiteboard/OBS.jpg" width="100" height="100"><br><span>Hazards/Safe Acts</span></a>

<img title="Hazards/Safe Acts" border="0" alt="Hazards/Safe Acts" src="/Images/Whiteboard/OBS.jpg" width="100" height="100"><br><span>Hazards/Safe Acts</span>

<br/>

<span>Hazards/Safe Acts</span>

我尝试的VBA代码:

For Each ele In IE.document.getelementsbytagname("a")
 If InStr(ele.innerhtml, "OBS.jpg") > 0 Then
 ele.Click

 Exit For

End If

我出错的任何想法?

1 个答案:

答案 0 :(得分:0)

尝试

For Each htma In doc.getElementsByTagName("a")
    Set htmImgs = htma.getElementsByTagName("img")
    If Not htmImgs is nothing Then
        If htmImgs(0).getAttribute("src") <> vbNull And InStr(htmImgs(0).getAttribute("src"), "Images/Whiteboard/OBS.jpg") <> 0 Then
            htma.Click
            Exit For
        End If
    End If
Next