繁体   English   中英

更新MS Power Point链接对象,例如图表或Excel工作表

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

我有一个每周生成的ppt。 我已经创建了一个vbscript来更新链接的图表..但是我找不到如何识别我用来在ppt中创建表格的Excel工作表...

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

您目前正在检查图表的每个形状,需要添加ElseIf来测试形状.HasTable

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

暂无
暂无

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

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