4

我的问题是我已将图表粘贴到中,我正在尝试通过 Excel-VBA 更新嵌入的链接。

我尝试了以下代码但失败了:

代码 1

    AppPPT.Presentations.Open "D:\Demo.pptx", Untitled:=msoTrue
    AppPPT.ActivePresentation.UpdateLinks
    AppPPT.ActivePresentation.SaveAs "D:\Demo.pptx"

代码 2

    For i = 1 To AppPPT.ActivePresentation.Slides.Count
    For s = 1 To AppPPT.ActivePresentation.Slides(i).Shapes.Count
        If AppPPT.ActivePresentation.Slides(i).Shapes(s).Type = msoLinkedOLEObject Then
            AppPPT.ActivePresentation.Slides(i).Shapes(s).LinkFormat.Update
        End If
    Next s
Next i

代码 3

    Set PPTTemplate = AppPPT.Presentations.Open("D:\Demo.pptx")

    ' update chart
    Dim osld As Slide
    Dim oshp As PowerPoint.Shape

    For Each osld In PPTTemplate.Slides
    For Each oshp In osld.Shapes
    With oshp
    If .HasChart Then
    .Chart.ChartData.Activate
    .Chart.ChartData.Workbook.Close
    .Chart.Refresh
    End If
    End With
    Next oshp
    Next osld

    AppPPT.Activate
4

2 回答 2

5

我通过花了几天时间尝试实现了它

AppPPT.ActivePresentation.Slides(1).Shapes("Chart 75").LinkFormat.Update

和断线代码

AppPPT.ActivePresentation.Slides(1).Shapes("Chart 75").LinkFormat.BreakLink
于 2013-02-27T10:07:07.243 回答
1

谢谢!一旦我能够识别对象/图表#,它就起作用了。(单击一个对象,在绘图工具、排列、选择窗格下。)这是我的代码。现在我可以运行它,它会立即更新我的所有链接。我不想将其设置为自动更新,因为当我将其发送出去时,收件人会收到一条关于链接的警告消息,这令人困惑。再次感谢。

Sub update()

ActivePresentation.Slides(1).Shapes("Object 1").LinkFormat.update
ActivePresentation.Slides(1).Shapes("Object 2").LinkFormat.update

ActivePresentation.Slides(4).Shapes("Chart 5").LinkFormat.update

ActivePresentation.Slides(5).Shapes("Object 2").LinkFormat.update
ActivePresentation.Slides(5).Shapes("Chart 5").LinkFormat.update

ActivePresentation.Slides(6).Shapes("Object 1").LinkFormat.update
ActivePresentation.Slides(6).Shapes("Chart 4").LinkFormat.update
ActivePresentation.Slides(6).Shapes("Chart 6").LinkFormat.update

ActivePresentation.Slides(7).Shapes("Object 1").LinkFormat.update
ActivePresentation.Slides(7).Shapes("Chart 4").LinkFormat.update
ActivePresentation.Slides(7).Shapes("Chart 5").LinkFormat.update

ActivePresentation.Slides(8).Shapes("Object 3").LinkFormat.update

ActivePresentation.Slides(9).Shapes("Chart 4").LinkFormat.update

ActivePresentation.Slides(10).Shapes("Object 1").LinkFormat.update

ActivePresentation.Slides(11).Shapes("Object 6").LinkFormat.update
ActivePresentation.Slides(11).Shapes("Object 7").LinkFormat.update
ActivePresentation.Slides(11).Shapes("Object 8").LinkFormat.update

End Sub
于 2017-10-13T20:51:33.313 回答