我相信我需要調用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如何從vba中查找和調用javascript方法
我不能發佈一個鏈接,因爲它需要登錄訪問它...請讓我知道如果您需要更大的示例代碼來理解我的問題。
我相信我需要引用「導出爲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:()函數,但我得到運行時錯誤無法完成,由於操作錯誤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](https://msdn.microsoft.com/en-us/library/ms536420%28v=vs.85%29.aspx)。 – dee
嗨迪我跟着你的鏈接,並試圖這兩件事..我試圖從VBA運行,所以我不能使用var ...'Dim getFunction =「get:function(_shouldhaverowaction(this.export,C)),( Dim exportNow'eval(「exportNow = new」+ getFunction +「;」)**我也嘗試過**調用objIE.HTMLDocument.eval() 「get:function(_shouldhaverowaction(this.export,C)),(b.getPlugin(chr(34)printplugin chr(34)))」,「JavaScript」)I GOT THE OBJECT DOESNT SUPPORT THIS PROPERTY OR METHOD ERROR .. – Kdunc2015