나는 HTML 테이블에있는 이미지를 클릭하는 VBA 코드를 작성하려고 노력해 왔습니다. 내가 클릭하려고하는 이미지에는 소스 코드 만 있습니다.VBA를 클릭하여 html 테이블에 넣은 이미지
나는 이미지를 클릭하는 데 4 가지 방법을 시도했지만이 중 아무 것도 작동하지 않았습니다. 누구든지 VBA 코드를 작성하는 방법을 도울 수 있습니까?
1.
Dim HTMLDoc As Object
Set HTMLDoc = IE.document
Dim ElementCol As Object
Set ElementCol = HTMLDoc.getElementsByTagName("td")
For Each link In ElementCol
If link.innerHTML = "excel.jpg" Then
link.Click
Exit For
End If
Next link
2.
Dim HTMLDoc As Object
Set HTMLDoc = IE.document
Dim i As Object
For Each i In HTMLDoc.images
If i.src = "../images/excel.jpg" Then
i.Click
Exit for
End If
Next i
3.
Dim HTMLDoc As Object
Set HTMLDoc = IE.document
Dim img As Object
For Each img In HTMLDoc.all
If img.innerHTML = "excel.jpg" Then
img.Click
Exit For
End If
Next img
4.
Dim HTMLDoc As Object
Set HTMLDoc = site.document
Dim tdCollection As Object
Set tdCollection = HTMLDoc.all
For Each cell In tdCollection
If cell.ID = "singleXLS" Then
cell.Click
Exit Sub
End If
Next
그는 re는 HTML 코드입니다.
제안으로<tbody><tr>
<td id="singleXLS" onclick="javascript:gCognosViewer.getRV().viewReport('spreadsheetML');" return="" true;"="" style="cursor:hand;" valign="middle" align="center">
<img src="../images/excel.jpg" border="0"></td>
<td> </td>
, 여기 내가 사용하고있는 코드입니다.
Sub click_img()
Dim URL As String
Dim HTMLDoc As Object
Set site = CreateObject("internetexplorer.application")
URL = Range("B2").Value 'There is an URL in cell B2
site.navigate URL
site.Visible = True
While site.busy
Wend
Do Until site.readyState = 4
DoEvents
Loop
Set HTMLDoc = site.Document
HTMLDoc.getElementById("singleXLS").getElementsByTagName("img")(0).Click 'Error is here
End Sub
HTMLDoc.getElementbyId을 핀 도움이 될 것입니다 (" singleXLS "). getElementsbyTagName ("img ") (0). 클릭 –
빠른 응답 Tim을 보내 주셔서 감사합니다. 나는 이것을 시도했다. 하지만 런타임 오류 424 가져 오는 중 : 개체 필요합니다. 도와 주실 수 있겠습니까? – Prakash
내가 게시 한 코드는 귀하가 제공 한 HTML을 사용해야합니다. 현재 코드를 게시하는 데 도움이 될 것입니다. –