简体   繁体   English

Excel VBA-导出和保存SSRS报告

[英]Excel VBA - Exporting and saving SSRS report

Looking for help with pulling an SSRS report from an internal company site using VBA. 在使用VBA从公司内部站点获取SSRS报告方面寻求帮助。 I've read several posts on VBA automation and have been managed to successfully make all the selections and run the report, now I just need the data. 我已经阅读了几篇有关VBA自动化的文章,并且已经成功地进行了所有选择和运行报告,现在我只需要数据。

Specifically, I need help to select the export to excel option. 具体来说,我需要帮助来选择“导出到Excel”选项。

My current VBA code: 我当前的VBA代码:

Sub macro_07()
Dim appIE As InternetExplorerMedium
'Set appIE = Nothing
Dim objElement As Object
Dim objCollection As Object
Dim objCollection2 As Object
Dim objCollection3 As Object
Dim objCollection4 As Object
Dim objCollection5 As Object
Dim objCollection6 As Object
Dim objCollection7 As Object
Dim objCollection8 As Object

Set appIE = New InternetExplorerMedium
sURL = ThisWorkbook.Sheets("Control").Range("IALinks").Cells(1, 1).Value
With appIE
    .Navigate sURL
    .Visible = True
End With

Do While appIE.Busy Or appIE.readyState <> 4
    DoEvents
Loop

Set objCollection = appIE.document.getElementById("ctl31_ctl04_ctl07_txtValue")
objCollection.Value = Range("YearSlct").Value
Set objCollection2 = appIE.document.getElementById("ctl31_ctl04_ctl03_ddValue")
objCollection2.selectedIndex = 4
objCollection2.FireEvent "onchange"
Application.Wait (Now + TimeValue("0:00:002"))
Set objCollection3 = appIE.document.getElementById("ctl31_ctl04_ctl05")
objCollection3.Click
Set objCollection4 = appIE.document.getElementById("ctl31_ctl04_ctl05_divDropDown_ctl01")
objCollection4.Focus
objCollection4.Checked = "checked"
Set objCollection5 = appIE.document.getElementById("ctl31_ctl04_ctl05_divDropDown_ctl03")
objCollection5.Focus
objCollection5.Checked = "checked"
objCollection5.FireEvent "onchange"

Set objCollection6 = appIE.document.getElementById("ctl31_ctl04_ctl00")
objCollection6.Click
Application.Wait (Now + TimeValue("0:00:002"))

Set objCollection7 = appIE.document.getElementById("ctl31_ctl06_ctl04_ctl00_Button")
objCollection7.Click


  Set appIE = Nothing
End Sub

This gets me to the point of selecting the export button but I can't figure out how to select the excel option. 这使我选择了导出按钮,但是我不知道如何选择excel选项。

Export Menu: 导出菜单:

导出菜单

Here is the HTML code from the site: 这是该站点的HTML代码:

<table style="display:inline;" cellspacing="0" cellpadding="0">
                        <tbody><tr>
                            <td height="28"><div class="HoverButton" id="ctl31_ctl06_ctl04_ctl00">
                                <table title="Export" id="ctl31_ctl06_ctl04_ctl00_Button" border="0">
                                    <tbody><tr>
                                        <td><a id="ctl31_ctl06_ctl04_ctl00_ButtonLink" style="cursor: pointer;" href="javascript:void(0)"><img id="ctl31_ctl06_ctl04_ctl00_ButtonImg" style="border-style:None;height:16px;width:16px;border-width:0px;" src="/Reports/Reserved.ReportViewerWebControl.axd?OpType=Resource&amp;Version=10.50.1600.1&amp;Name=Microsoft.Reporting.WebForms.Icons.Export.gif"><img id="ctl31_ctl06_ctl04_ctl00_ButtonImgDown" style="border-style:None;height:6px;width:7px;border-width:0px;margin-bottom:5px;margin-left:5px;" src="/Reports/Reserved.ReportViewerWebControl.axd?OpType=Resource&amp;Version=10.50.1600.1&amp;Name=Microsoft.Reporting.WebForms.Icons.ArrowDown.gif"></a></td>
                                    </tr>
                                </tbody></table>
                            </div><div class="MenuBarBkGnd" id="ctl31_ctl06_ctl04_ctl00_Menu" style="padding: 1px; display: block; visibility: visible; position: absolute;">
                                <div class="HoverButton">
                                    <a class="ActiveLink" style="padding: 3px 8px 3px 32px; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ctl31').exportReport('XML');" href="javascript:void(0)">XML file with report data</a>
                                </div><div class="DisabledButton">
                                    <a class="ActiveLink" style="padding: 3px 8px 3px 32px; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ctl31').exportReport('CSV');" href="javascript:void(0)">CSV (comma delimited)</a>
                                </div><div class="DisabledButton">
                                    <a class="ActiveLink" style="padding: 3px 8px 3px 32px; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ctl31').exportReport('PDF');" href="javascript:void(0)">PDF</a>
                                </div><div class="DisabledButton">
                                    <a class="ActiveLink" style="padding: 3px 8px 3px 32px; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ctl31').exportReport('MHTML');" href="javascript:void(0)">MHTML (web archive)</a>
                                </div><div class="DisabledButton">
                                    <a class="ActiveLink" style="padding: 3px 8px 3px 32px; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ctl31').exportReport('EXCEL');" href="javascript:void(0)">Excel</a>
                                </div><div class="DisabledButton">
                                    <a class="ActiveLink" style="padding: 3px 8px 3px 32px; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ctl31').exportReport('IMAGE');" href="javascript:void(0)">TIFF file</a>
                                </div><div class="DisabledButton">
                                    <a class="ActiveLink" style="padding: 3px 8px 3px 32px; text-decoration: none; display: block; white-space: nowrap;" onclick="$find('ctl31').exportReport('WORD');" href="javascript:void(0)">Word</a>
                                </div>
                            <div style="left: 0px; top: 0px; width: 26px; height: 149px; filter: none; position: absolute; z-index: -1; opacity: 0.05; background-color: black;"></div></div></td>
                        </tr>
                    </tbody></table>

Set up a subscription to the report and Report Server will do the export to excel to a fileshare for you. 设置报表的订阅,Report Server将为您导出到excel文件共享。

Alternately you might want to investigate the database query behind the report and (re)create the report into Excel. 或者,您可能想调查报告后面的数据库查询,然后将报告重新创建到Excel中。

https://docs.microsoft.com/en-us/sql/reporting-services/subscriptions/subscriptions-and-delivery-reporting-services?view=sql-server-2017 https://docs.microsoft.com/zh-cn/sql/reporting-services/subscriptions/subscriptions-and-delivery-reporting-services?view=sql-server-2017

Thanks all for the notes. 谢谢大家的笔记。 I was able to find a solution following Ryan's suggestion and checking out an answer he provided on a prior post ( Get all innertext VBA ) 我能够根据Ryan的建议找到解决方案,并查看他在先前的帖子中提供的答案( 获取所有innertext VBA

From there it was a simple loop: 从那里开始是一个简单的循环:

    For Each Element In Elements
        If Element.innerText = "Excel" Then Element.Click
    Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM