我最初在这里Excel VBA HTML Click Button/Hyperlinks问了一个问题,但经过编辑和更改后有点迷路。经过数小时的进一步研究和审查我的网页,我发现了另一种获得期望结果的方法。
由于单击超链接似乎无效,因此我可以单击另一个具有下拉选项的按钮,然后我还需要单击该按钮才能到达同一点(与原始超链接方法相同)。 / p>
按钮的“检查元素”和下拉菜单如下。还有我更新的代码。
结果-单击按钮“转到”,然后选择下拉选项“详细信息”。
另外,请忽略sendkey,我知道它们是不得已的方法,但是暂时可以。
检查元素“转到”:
<a title="Go To - Menu button - To open the menu press spacebar" class="urTbarBtnStd" id="SRES2_BUT_GOTO" onkeypress="sapUrMapi_ToolbarButton_openMenu('SRES2_BUT_GOTO',event);return false;" onclick="sapUrMapi_ToolbarButton_openMenu('SRES2_BUT_GOTO',event);return false;" href="javascript:void(0);" ct="ToolbarButton"><span style="white-space: nowrap;">Go To <img align="baseline" class="urTbarBtnMnuIco" src="1x1"></span></a>
检查元素“详细信息”:
<tr class="urMnuRowOn" id="EDIT_DETAILS" onclick="me.htmlbSL(this,78,'SRES2_GOTO:onSelectPopupMenuItem','','EDIT_DETAILS','Details');;me.sapUrMapi_PopupMenu_hideAll();return false;" Idx="0"><td width="17" class="urMnuChk" style="width: 17px;"> </td><td width="4" style="width: 4px;"> </td><td width="40" class="urMnuTxt" nowrap="" style="width: 40px;"><span style="white-space: nowrap;">Details</span></td><td width="15" class="urMnuSub" style="width: 15px;"> </td></tr>
Sub TPMRebates()
Dim objIE As InternetExplorer
Dim aEle As Object 'HTMLLinkElement
Dim y As Integer
Dim result As String
Dim Link As Object
Dim ElementCol As Object
Dim wkbSourceWB As Workbook
Dim SourceShtClm As Worksheet
Set wkbSourceWB = ThisWorkbook 'Set workbook
Set SourceShtClm = wkbSourceWB.Sheets("Claim Summary")
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "<very long intranet website>"
Do While objIE.readyState = 4: DoEvents: Loop
Application.Wait Now + TimeSerial(0, 0, 4) 'wait 4 sec
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Enter}"
Application.Wait Time + TimeSerial(0, 0, 6)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SendKeys "{Tab}"
Application.Wait (Now + 0.000001)
SourceShtClm.Range("N4").Copy
SendKeys "^v"
SendKeys "{Enter}"
Application.Wait Time + TimeSerial(0, 0, 10)
'*****************************
'
'This is where I need the code to click 'go to' then 'details'
'
'*****************************
'Have tried things like objIE.document.getElementsByTagName("a")
'For Each Link In ElementCol
' Debug.Print Link.innerText
' If Link.innerText Like "Go To - Menu button - To open the menu press spacebar" Then
' Link.Click
' Exit For
' End If
'Next Link
'
'
'Also tried things like; objIE.document.getElementsByID("SRES2_BUT_GOTO").Click also .Focus but nothing works
End Sub
答案 0 :(得分:1)
Dim HTMLdoc As HTMLDocument
Dim frame As HTMLFrameElement
Dim img As HTMLImg
Set HTMLdoc = objIE.document
Set frame = HTMLdoc.getElementsByName("crmA")(0)
Set HTMLdoc = frame.contentDocument
Set img = HTMLdoc.getElementById("SRES2_BUT_GOTO")
img.Click