7 Replies Latest reply: Apr 8, 2016 12:22 PM by Walter Sr RSS

    How to Export a single Chart to Excel based on User Selection?

      Hi All,

       

      I am trying to export a chart (only the currently viewed chart) when selected by a user after pressing a button.

       

      Currently I have an input box (with drop down enabled) to select which chart is shown. Only the chart selected in the input box is shown (all others are conditionally hidden).

       

      I want the button to export a given chart to excel. I can have the button function as follows:

       

           SUB ReportSelection

           SET chart=ActiveDocument.GetSheetObject("CH01")

           SET p = chart.GetProperties

           chart.SendToExcel

           END SUB


      However I would have to create a separate button for each chart.

       

       

      If I did this:

       

           SUB ReportSelection

               For i = 0 To ActiveDocument.NoOfSheets - 1

                   Set MySheet = ActiveDocument.GetSheet(i)

                   MyCharts=MySheet.GetSheetObjects

                       For X =lbound(MyCharts) to ubound(MyCharts)

                               ActiveDocument.Sheets(i).Activate

                                Set obj = ActiveDocument.GetSheetObject(MyCharts(X).GetObjectId)

                                IF Obj.GetObjectType = 10 Then

                                          SET chart=ActiveDocument.GetSheetObject(MyCharts(X).GetObjectId)

                                                                       SET p = chart.GetProperties

                                                                       chart.SendToExcel

                            End if

                       Next

               Next 

           End Sub

       

      The Macro goes through and prints out all four charts I have created.


      Is there a way to only print out the current chart the user is viewing?

       

      Any help would be greatly appreciated. Thanks!