使用VBA在IE网页中单击链接/按钮 [英] Using VBA to click on a link/button in an IE web page

查看:487
本文介绍了使用VBA在IE网页中单击链接/按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了很多有关使用VBA在IE中单击链接的信息,但是在我的情况下我无法使其正常工作. 相关的HTML代码如下:

I have read a lot of information on using VBA to click on a link in IE, but I cannot get it to work in my case. The relevant HTML code is as follows:

<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次不同的尝试)如下:

The VBA code I have tried, with 3 different attempts noted, is as follows:

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

任何对我可能做错了事情的想法或其他建议将不胜感激.

Any thoughts on what I might be doing wrong or other suggestions would greatly be appreciated.

TMc

推荐答案

<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>

您要单击的是锚(a)标记,而不是div.因此,您可以找到具有其ID的div,然后单击其唯一且唯一的子项

What you want to click on is the anchor (a) tag, not the div. So, you can find the div with its id and then click on its one and only child with

button.Children(0).Click

这篇关于使用VBA在IE网页中单击链接/按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆