简体   繁体   中英

Open Power Point chart data in Excel

I'm trying to create a macro to clean up the Excel sheets behind charts in power point so that only the data being used in the chart is there, and there are no formulas.

I've pieced together this, which works when I open the chart data in Excel, but I'm hoping I can create a macro that cycles through each chart in the workbook and opens the chart data in Excel for me, so I can perform the following on each.

Sub ChartCleaningPP()

'Paste values of table

    Range("Table1[#All]").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
    Dim Cell As Range

'clear other cells

For Each Cell In ActiveSheet.UsedRange
If Intersect(Cell, Selection) Is Nothing Then
Cell.Clear
End If
Next Cell

'remove hidden

For lp = 256 To 1 Step -1
If Columns(lp).EntireColumn.Hidden = True Then Columns(lp).EntireColumn.Delete Else
Next
For lp = 65536 To 1 Step -1
If Rows(lp).EntireRow.Hidden = True Then Rows(lp).EntireRow.Delete Else
Next

'close window

ActiveWindow.Close

End Sub

Try this:

Sub ChangeCharts()
Dim ws As Worksheet
Dim myChart As ChartObject

   For Each ws In ThisWorkbook.Worksheets
      For Each myChart In ws.ChartObjects
        'your code here
        'i.e Call ChartCleaningPP
        Next myChart
    Next ws
End Sub

EDIT: (Run Excel Makro from PP) Need to activate MS Excel Libraries in PP.

Sub RunExcelMakro()
Dim wk As Object
Dim Path As String
CreateObject ("Excel.Application")
Set xlApp = New Excel.Application
xlApp.Visible = True

Path = "C:\Users\User\Desktop\F\1.xlsm" 'Edit Path
Set wk = xlApp.Workbooks.Open(Path)

xlApp.Run "YourMakro"

xlApp.Quit
End Sub

EDIT:

Sub M1()
    Dim sld As Slide
    Dim sh As Shape
    Dim Path As String

    Dim xlApp As Object
    Set xlApp = CreateObject("Excel.Application")
    xlApp.Visible = True

    For Each sld In ActivePresentation.Slides
        For Each sh In sld.Shapes
            If sh.Type = msoLinkedOLEObject Then
                With sh.LinkFormat
                    Path = .SourceFullName
                    xlApp.Workbooks.Open Path

                End With
            End If
        Next sh
    Next sld
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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