我最初在这里问了一个问题Excel VBA HTML Click Button/Hyperlinks但经过编辑和更改,有点迷失了。经过数小时的进一步研究和审查我的网页,我找到了另一种方法来达到我想要的结果。
由于单击超链接似乎不起作用,因此我可以单击另一个按钮,该按钮有一个下拉选项,然后我还需要单击该选项才能到达同一点(与原始超链接方法相同)。
按钮的“检查元素”和下拉菜单如下。我的更新代码如下。
结果 - 单击“转到”按钮,然后选择下拉选项“详细信息”..
另外,请忽略 sendkeys,我知道它们是最后的手段,但目前它有效。
检查元素“转到”:
<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
最佳答案
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
关于javascript - EXCEL VBA HTML 单击按钮,然后单击下拉选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52787939/