簡體   English   中英

如何使用Excel onclick自動執行Excel以從Internet Explorer下載PDF

[英]How to automate Excel to download PDF from Internet Explorer using Javascript onclick

我有一個自動化Internet Explorer的代碼,IE可見性設置為false,以便代碼在后台運行。 我的代碼單擊一個元素ID,這將打開一個單獨的IE窗口,該窗口可見且包含PDF報告。 不幸的是,我一直無法打開新的IE窗口,但仍然不可見,無法將PDF副本下載到計算機桌面。

我嘗試直接導航到帶有報告的新打開頁面的鏈接,但是鏈接可能會有所不同。

我在網站上單擊元素“ btnContinue”以打開報告:

<input name="btnContinue" class="btn btn-primary" id="btnContinue" onclick="javascript:pop('Splash.aspx?SplashID=3&amp;../Reports/View.aspx&amp;ReporttypeID=1&amp;lang=EN&amp;ruletypeid=5&amp;ruleid=0'); return false;" type="submit" value="Continue">

這是我的代碼:

Sub navigate()
Const url = "https://myURL"
Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")    
With ie 'Open IE
    .navigate url
    ieBusy ie
    .Visible = False
        If Item.ID = "btnNextPage" Then
            Item.Click
            Exit For
        End If
    Next
    ieBusy ie
‘Below code clicks the element ID and opens a new IE with the report – Code needs to open a new IE but visibility remain false and download the newly opened report OR report triggered to be downloaded directly from element/javascript onclick.        
For Each Item In ie.document.all
        If Item.ID = "btnContinue" Then
            Item.Click
            Exit For
        End If
    Next
    ieBusy ie        
End With 'End IE actions
End Sub
Sub ieBusy(ie As Object)
Do While ie.Busy Or ie.ReadyState < 4
    DoEvents
Loop 'Loop
End Sub

我需要此代碼來打開新頁面,保持不可見,並將PDF下載到桌面上,或者以某種方式觸發報表從onclick下載(如果可能),而無需通過單擊元素來打開新頁面。 我試圖導航/觸發javascript onclick事件,以查看是否可以直接下載報告,而無需單擊元素以在新窗口中打開報告,但不幸的是沒有成功。 任何幫助將不勝感激。

不幸的是,我無法獲得涉及導航到/觸發javascript的任何解決方案,但是經過大量挖掘工作之后,我試圖實現自動化,但最終我能夠確定並提取有效執行相同操作的URL。 因此,盡管我找不到解決方案,但@Tragamor的解決方案為我工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM