获取IE以使用VBA EXCEL单击LI链接

时间:2018-03-28 20:38:04

标签: excel vba

我正在尝试让我的代码点击javascript li链接或执行javascript代码,其中一个可以解决我的问题。

这是我的代码:

Block

我也尝试过:

Sub submitlogin()

Dim IE As Object
    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True
    IE.Navigate "http://blablabla/"


 While IE.busy: DoEvents: Wend
 On Error Resume Next


IE.Document.getElementsByTagName("a").Item(4).Click 'doesn´t work

并尝试过:

IE.Document.parentWindow.execScript "checkcontained();", "javascript" 'also not working

这是HTML:

 Set ObjA = IE.Document.getElementByID("foldinglist").getElementsByTagName("a")(0)
  ObjA.Click 'also not working


  End Sub

我必须在这里点击(或执行):

<body class="menu">
<div id="menu">
    <div align="left" id="text" style="position:absolute;top:0px;left:40px; width: 200px; height: 19px;display:none;"><strong><b>[TimeS]</b></strong></div>
    <div align="left" id="idMenu" style="position:absolute;top:18px;left:7px; width: 200px; height: 19px; display:none;"></div>
<div id="treeview">
<div id="menu_d">
<ul style=""><li id="foldheader0" onClick="JavaScript: checkcontained();">time control
<ul id="foldinglist" style="DISPLAY:none;" onClick="JavaScript: checkcontained();"><li id="foldheader1" onClick="JavaScript: checkcontained();">Maintenance
<ul id="foldinglist" style="DISPLAY:none;" onClick="JavaScript: checkcontained();"><li><a href="JavaScript: chamaPagina('../../thisthat.asp', '');">admin</a></li></ul></li>
<li id="foldheader1" onClick="JavaScript: checkcontained();">Consult/Reports
<ul id="foldinglist" style="DISPLAY:none;" onClick="JavaScript: checkcontained();"><li><a href="JavaScript: chamaPagina('../../thisthat_redir.asp', '');">Demonst time</a></li></ul></li>
<li id="foldheader1" onClick="JavaScript: checkcontained();">help
<ul id="foldinglist" style="DISPLAY:none;" onClick="JavaScript: checkcontained();"><li><a href="JavaScript: chamaPagina('../thisthose.html', '');">PortariRE</a></li></ul></li>

        </ul>
        <form name="frmMenu"><input type="hidden" id="txtmaxnivel" name="txtmaxnivel" value="1" /></form>

1 个答案:

答案 0 :(得分:0)

也许这篇文章可以提供帮助: How to do onclick event in VBA/VBScript

但是,如果您尝试使用FireEvent,我觉得您应该在ul标签上使用该事件。