Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript VBA onclick事件Internet Explorer不工作_Javascript_Excel_Vba - Fatal编程技术网

Javascript VBA onclick事件Internet Explorer不工作

Javascript VBA onclick事件Internet Explorer不工作,javascript,excel,vba,Javascript,Excel,Vba,我是VBA新手,我正在尝试自动化web Explorer导航,但有很多困难。 我编写了一个脚本,可以导航到网页并搜索代码。结果是一个表格(“dr表格单元格富表格单元格”),其中一行包含搜索项(“020900062571”),显示为指向另一页的链接。下面是该表的代码: <td class="dr-table-cell rich-table-cell" id="formRicercaPdr:pdrTable:0:j_id134"> <a onclick="if(

我是VBA新手,我正在尝试自动化web Explorer导航,但有很多困难。 我编写了一个脚本,可以导航到网页并搜索代码。结果是一个表格(“dr表格单元格富表格单元格”),其中一行包含搜索项(“020900062571”),显示为指向另一页的链接。下面是该表的代码:

<td class="dr-table-cell rich-table-cell" 
    id="formRicercaPdr:pdrTable:0:j_id134">
     <a onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.forms['formRicercaPdr'],'formRicercaPdr:pdrTable:0:j_id136,formRicercaPdr:pdrTable:0:j_id136','');}return false" 
         href="#">02090000062571</a>
 </td>

我的问题是单击“020900062571”href按钮(是搜索的项目)并执行显示另一个表的javascript函数

这是我的代码:

Sub TriggerDivClick()
Dim ie As SHDocVw.InternetExplorer
Dim doc As MSHTML.HTMLDocument
Dim div As HTMLDivElement
Dim url As String

url = "some URL"

Set ie = New SHDocVw.InternetExplorer

ie.Visible = True
ie.Navigate url

While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE
    DoEvents
Wend
Set pdr_button = ie.Document.getElementsByClassName("dr-table-cell rich-table-cell")
For Each a In pdr_button
'here comes the problems 

a.Item(0).FireEvent ("click()")

Next a 
Sub-TriggerDivClick()
Dim ie作为SHDocVw.InternetExplorer
Dim doc作为MSHTML.HTMLDocument
Dim div作为HTMLDIVELENT
将url设置为字符串
url=“一些url”
设置ie=New SHDocVw.InternetExplorer
可见=真实
浏览网址
当ie忙或ie ReadyState ReadyState\u完成时
多芬特
温德
设置pdr_按钮=ie.Document.getElementsByClassName(“dr表格单元格富表格单元格”)
对于pdr_按钮中的每个a
“问题来了
a、 项(0).FireEvent(“单击()”)
下一个
端接头

我可以找到该项目,但我无法执行代码以按下按钮。 我用的是IE 11

谢谢你的耐心

这应该有效:

ie.Document.getElementById("formRicercaPdr:pdrTable:0:j_id13‌​4"). _
     getElementsByTag‌​Name("a")(0).Click  

ie.Document.getElementById(“formRicercaPdr:pdrTable:0:j_id134”).getElementsByTagName(“a”)(0)。单击
你太棒了!!!请告诉我在哪里可以找到关于DOM和HTML初学者的完整文档。感谢大多数HTMLDOM相关文档都是基于Javascript的,但通常可以适应VBA而不需要太多麻烦。也许从这里开始:@TimWilliams,你应该回答这个问题,我会投票表决,这肯定会帮助其他人。嗨,tim Sory,如果有人以这种方式与你联系,但我在iframe中有一个按钮。如果你能花几分钟看看这个问题,我会很高兴的。这篇文章是“如何在IFrame vba中单击按钮”,提前感谢