【发布时间】:2015-10-09 20:29:13
【问题描述】:
我相信我需要调用 javascript 方法而不是尝试触发按钮。我尝试了以下示例,我认为我的问题是我不知道应该使用代码的哪些部分..Click button or execute JavaScript function with VBA 和这个http://www.vbaexpress.com/forum/showthread.php?9690-Solved-call-a-javascript-function 和http://www.vbforums.com/showthread.php?650771-RESOLVED-How-to-Call-a-JavaScript-function-From-Visual-Basic-6-WITH-wanted-parameters
我无法发布链接,因为它需要登录才能访问它...如果您需要更大的代码示例来理解我的问题,请告诉我。
我相信我需要一个引用“导出为 CSV”的函数,但我不确定要调用哪个函数以及要在调用中包含哪些函数部分...以下来自 catalog.js
function()
{var a=window.Ext4||window.Ext;a.define ("Rally.alm.ui.page.plugins.PageToolFactory",{singleton:true,mixins: {messageable:Rally.Messageable},PRINT:"PRINT",IMPORT:"IMPORT",EXPORT:"EXPORT",ge t:function(c,b)
{var d=[];
if(this._shouldHaveRowAction(this.PRINT,c))
{
if(b.getPlugin("printplugin"))
{
d.push({text:"Print...",handler:b.getPlugin("printplugin").print,cls:"page- tools",scope:b.getPlugin("printplugin"),addInteractionClass:true})}}
if(this._shouldHaveRowAction(this.IMPORT,c))
{
if(b.getPlugin("printplugin"))
{
d.push({text:"Import User Stories...",handler:a.emptyFn})}}
if(this._shouldHaveRowAction(this.EXPORT,c))
{
if(b.getPlugin("printplugin"))
{
d.push({text:"Export as CSV",handler:a.emptyFn})}} return d}
下一个示例来自 yui.js...
(function()
{
RALLY.ui.menu.AvailablePageTools=Ext.extend(Object, {constructor:function()
{
this.PRINT={text:'Print...',slug:'print'};
this.EMAIL={text:'Email...',slug:'email'};
this.SAVE={text:'Save...',slug:'save'};
this.CSV_IMPORT={text:'Import User Stories...',slug:'csvimport'};
this.CSV_IMPORT_PORTFOLIO_ITEM={text:'Import Portfolio Items...',slug:'csvimport'};
this.CSV_EXPORT={text:'Export as CSV',slug:'csvexport'};
this.PDF_EXPORT={text:'Export as PDF',slug:'pdfexport'};
我已经在我的 vba 脚本中尝试了这些选项..
Dim objIE As SHDocVw.InternetExplorer 'microsoft internet controls (shdocvw.dll)
Dim htmlDoc As MSHTML.HTMLDocument 'Microsoft HTML Object Library
Dim htmlInput As MSHTML.HTMLInputElement
Dim htmlColl As MSHTML.IHTMLElementCollection
Dim CurrentWindow As HTMLWindowProxy
'Set objIE = Nothing
Set objIE = New SHDocVw.InternetExplorer
ThisWorkbook.Worksheets("Sheet1").Activate
With objIE
.navigate "website"
.Visible = 1
Do While .readyState <> 4: DoEvents: Loop
Application.Wait (Now + TimeValue("0:00:02"))
Set htmlDoc = .document
objIE.document.all.Item
'Set CurrentWindow = objIE.htmlDoc.parentWindow
'no error no export
'Call objIE.document.parentWindow.execScript("_exportHandler:Function()", "JavaScript")
'no error no export
'Call objIE.document.parentWindow.execScript("_getExportItems:Function()", "JavaScript")
'RUN TIME ERROR could not complete the operation due to error 80020101 (error while evaluating js)
'Call objIE.document.parentWindow.execScript("_a.define()", "JavaScript")
'run time error the object invoked has disconnected from its clients,
'RUN TIME ERROR could not complete the operation due to error 80020101 (error while evaluating js)
'Call objIE.document.parentWindow.execScript("_b.push()", "JavaScript")
'run time error the object invoked has disconnected from its clients,
'RUN TIME ERROR could not complete the operation due to error 80020101 (error while evaluating js)
'Call objIE.document.parentWindow.execScript("handler:function(){window.location=Rally.ui.grid.GridExport.buildCsvExportUrl(this.gridboard.getGridOrBoard())}", "JavaScript")
'Call objIE.document.parentWindow.execScript("b.push()", "JavaScript")
'Call objIE.document.parentWindow.execScript("c.push()", "JavaScript")
'RUN TIME ERROR could not complete the operation due to error 80020101 (error while evaluating js)
'Call objIE.document.parentWindow.execScript("this.CSV_Export()", "JavaScript")
'error the remote server machine does not exist or is unavailable
'Call objIE.document.parentWindow.execScript("constructor:function()", "JavaScript")
'Call objIE.document.parentWindow.execScript("constructor:function()", "JavaScript")
'object
Call CurrentWindow.execScript("d.push({text:CHR(34)Export as CSV CHR(34),handler:a.emptyFn})")
'ofile.SaveAs scrapeRally:=ofile.Name
'ofile.Close savechanges:=False
'objIE.Quit
Set objIE = Nothing
End With
End Sub
我正在尝试从 VBA 运行它,所以我不能使用 var...
Dim getFunction = "get:function (_shouldhaverowaction(this.export,C)),(b.getPlugin(chr(34)printplugin chr(34)))"
Dim exportNow
eval ("exportNow = new" + getFunction + ";")
我也试过了
Call objIE.HTMLDocument.eval("get:function (_shouldhaverowaction(this.export,C)),(b.getPlugin( chr(34) printplugin chr(34)))", "JavaScript")
我在尝试运行时收到“对象不支持此属性或方法”错误。
任何建议都会非常棒。
我刚刚遇到了另一个可能是我想要的函数,但我仍然不知道我应该使用它的哪一部分来调用它。我试图只调用 _getExportItems:function() 但我得到 RUN TIME ERROR 由于错误 80020101 无法完成操作(评估 js 时出错)
_getExportItems:function(){
var b=[];
if(this.enableCsvExport){
b.push({
text:"Export to CSV...",
handler:function(){
window.location=Rally.ui.grid.GridExport.buildCsvExportUrl (this.gridboard.getGridOrBoard())},scope:this})}
【问题讨论】:
-
execScript不再受支持。从 Internet Explorer 11 开始,使用 eval。 -
嗨,Dee 我按照你的链接尝试了这两件事。我试图从 VBA 运行它,所以我不能使用 var... 'Dim getFunction = "get:function (_shouldhaverowaction(this. export,C)),(b.getPlugin(chr(34)printplugin chr(34)))" 'Dim exportNow 'eval ("exportNow = new" + getFunction + ";") 我也试过了 调用 objIE.HTMLDocument.eval("get:function (_shouldhaverowaction(this.export,C)),(b.getPlugin( chr(34) printplugin chr(34)))", "JavaScript") 我得到了对象不支持此属性或方法错误..
标签: javascript vba