0
我已經閱讀了很多關於使用VBA在IE中單擊鏈接的信息,但是我無法在我的情況下使用它。 相關的HTML代碼如下:使用VBA點擊IE網頁中的鏈接/按鈕
<div id="LinkButton_3" widgetId="LinkButton_3">
<a class="Row_Icon" data-dojo-attach-point="linkNode" data-dojo-attach-event="onClick:_onLinkButtonClicked">Company XYZ. - #12345</a>
</div>
的VBA代碼,我已經試過了,有3次不同的嘗試說明,如下:
Dim ieApp As SHDocVw.InternetExplorer
Dim ieDoc As MSHTML.HTMLDocument
Dim button As HTMLInputButtonElement
Dim div As HTMLDivElement
' Create a new instance of IE
Set ieApp = New InternetExplorer
' Uncomment this line for debugging purposes.
ieApp.Visible = True
' Go to the page we're interested in.
ieApp.Navigate "MyURL.com"
Do While ieApp.Busy: DoEvents: Loop
Do Until ieApp.ReadyState = READYSTATE_COMPLETE: DoEvents: Loop
Set ieDoc = ieApp.Document
' Try #1.
' Nothing happened on the web page after these 3 lines were executed.
Set button = ieDoc.getElementById("LinkButton_3")
button.Focus
button.Click
' Try #2
' Nothing happens - button is not clicked.
Set div = ieDoc.getElementById("LinkButton_3")
div.FireEvent "onClick"
' Try #3
' Nothing happens - button is not clicked.
div.Click
' Close the instance of IE.
ieApp.Quit
' Clean up.
Set ieApp = Nothing
Set ieDoc = Nothing
什麼我可能是做錯了任何想法或其他建議將非常感激。
TMC
在試#1,'button.Children(0).Click'工作? –
馬特,你完全真棒!這確實奏效。幫助我瞭解button.Click和button.Children(0).Click之間的區別。再次感謝。 – TMc
你真正想要點擊的是div內的錨點(a)標籤。因此,你想要那個div的第一個孩子。這有幫助嗎? –