我的问题是我已将我的图表粘贴到powerpoint,我正在尝试通过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
答案 0 :(得分:5)
我已经花了几天时间试图实现它
AppPPT.ActivePresentation.Slides(1).Shapes("Chart 75").LinkFormat.Update
和BreakLines代码
AppPPT.ActivePresentation.Slides(1).Shapes("Chart 75").LinkFormat.BreakLink
答案 1 :(得分: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