简体   繁体   中英

Updating MS Power Point linked object such as chart or Excel sheet

I have a ppt which is generated every week. I have created a vbscript for updating the linked chart.. but i couldn't find how to identify the excel sheet which i have used for creating the table in the ppt...

Dim pptChart
    Dim pptChartData
    Dim xlWorkbook
    Dim sld
    Dim shp
'opent the ppt
    strPresPath = "C:\oldpptlocation.pptx"


   Set oPPTApp = CreateObject("PowerPoint.Application")
  oPPTApp.Visible = True
  Set oPPTFile = oPPTApp.Presentations.Open(strPresPath)


For Each sld In oPPTFile.Slides 'ActivePresentation.Slides
    For Each shp In sld.Shapes
        If shp.HasChart Then
            Set pptChart = shp.Chart
            Set pptChartData = pptChart.ChartData
            pptChartData.Activate
            Set pptWorkbook = pptChartData.Workbook
            On Error Resume Next
            'update first link
            pptWorkbook.UpdateLink pptWorkbook.LinkSources(1)
            'On Error GoTo 0
            pptChart.Refresh
            pptWorkbook.Close True

        End If

    Next
Next
oPPTFile.SaveAs ("C:\updated_ppt.pptx")
oPPTFile.Close
oPPTApp.Quit
Set pptWorkbook = Nothing
Set pptChartData = Nothing
Set pptChart = Nothing

You're currently checking each shape for a chart, you need to add an ElseIf to test whether the shape .HasTable .

If shp.HasChart Then
    'your code to update chart
ElseIf shp.HasTable Then
    'your code to update table
End If

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