簡體   English   中英

使用存在導出下拉菜單的VBA將IE報表導出到excel

[英]Export IE report to excel using VBA where export drop down menu exists

我正在使用vba從報表服務器中提取特定日期的報表。 通過在URL中輸入日期參數​​,我可以繞過日期選擇器。 下一步是將報告導出到excel。 它具有一個下拉列表來選擇文件類型。 如何獲取代碼以從下拉列表中選擇? 我嘗試了以下代碼的許多變體。

    Sub Report()
    Dim ie As Object
    Application.ScreenUpdating = False
    Set ie = CreateObject("Internetexplorer.Application")
    ie.Visible = True
    ie.navigate "http://reportserver.comp.local/ReportServer/Pages/ReportViewer.aspx?%2fOperations%2fAR%2fCash+Receipts&StartDate=2017-01-07&EndDate=2017-01-13"
    ie.document.getelementbyid("ReportViewerControl_ctl05_ctl04_ctl00_ButtonImgDown").Click
    ie.document.getelementbyid("ReportViewerControl_ctl05_ctl04_ctl00_Menu").Click
    ie.document.getelementbyid("ReportViewerControl_ctl05_ctl04_ctl00_Button").Value = "Excel"

您需要瀏覽下拉菜單選項並更改您要執行的特定選擇selectedIndex 請嘗試以下方法:

Option Explicit

Sub Report()
    Dim ie As Object, oSelection As Object, i As Long
    Application.ScreenUpdating = False
    Set ie = CreateObject("Internetexplorer.Application")
    If ie Is Nothing Then Exit Sub
    With ie
        .Visible = True
        .navigate "http://reportserver.comp.local/ReportServer/Pages/ReportViewer.aspx?%2fOperations%2fAR%2fCash+Receipts&StartDate=2017-01-07&EndDate=2017-01-13"

        ' I am guessing this is the right id check page source code "<select id='...'"
        Set oSelection = .document.getelementbyid("ReportViewerControl_ctl05_ctl04_ctl00_Menu")

        If Not oSelection Is Nothing Then
            For i = 0 To oSelection.all.Length - 1
                If InStr(1, oSelection.all(i), "Excel", vbTextCompare) > 0 Then
                    oSelection.selectedIndex = i
                    Exit For
                End If
            Next
            Set oSelection = Nothing
        End If
        .Quit
    End With
    Set ie = Nothing
    Application.ScreenUpdating = True
End Sub

暫無
暫無

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

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