单击按钮或使用VBA执行JavaScript函数 [英] Click button or execute JavaScript function with VBA

查看:413
本文介绍了单击按钮或使用VBA执行JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让我的VBA例程与一个使用JavaScript的页面进行交互,并且在过去取得了成功。最近更新后,它不再有效。在这一点上,我需要A)以编程方式点击按钮或B)执行按钮调用的功能。棘手的部分是按钮没有声明的名称。在源代码中有其他名称的名称,我可以与他们进行交互。这是源页面的html代码:

I'm trying to get my VBA routine to interact with a page that uses JavaScript, and have been successful in the past. After a recent update, it no longer works. At this point I need to either A) programmatically click a button or B) execute the function the button calls. The tricky part is that the button has no declared name. There are others on the sheet declared in the source code with names, and I can interact with them just fine. Here's the html code from the page source:

<input type="button" class="buttonForm" value='Run Report' onclick="exportData(workOrderSearchForm)"/>

如您所见,它不会声明该按钮的名称。过去,以下工作已经起作用:

As you can see, it does not declare a name for the button. In the past, the following has worked:

Set ie = CreateObject("InternetExplorer.application")
ie.document.all(79).Click

79是项目编号的索引。现在看来,该按钮已被更改为项目81,但简单地放入:

With "79" being the index of the item number. It now appears that the button has been changed to item "81", but simply putting in:

ie.document.all(81).Click

由于某种原因不起作用我知道要执行的函数:exportData(workOrderSearchForm),但不知道如何使用click方法。

is not working for some reason. I know the function I want to execute: exportData(workOrderSearchForm), but don't know how to do so outside of using the "click" method.

我有寻找一些关于IE应用程序对象的体面的文档,但似乎找不到一个好的源代码。有没有办法执行这个功能?

I've looked for some decent documentation regarding the IE application object, but can't seem to find a good source. Is there a way to execute the function?

推荐答案

尝试这样:

Dim CurrentWindow As HTMLWindowProxy: Set CurrentWindow = ie.Document.parentWindow
Call CurrentWindow.execScript("exportData(workOrderSearchForm)")

但首先,您需要在引用(工具>参考)下包含Microsoft HTML对象库

But first you will need to include Microsoft HTML Object Library under References (Tools>References)

这篇关于单击按钮或使用VBA执行JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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