vba 如何使用vba更新powerpoint 2010中嵌入的excel链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14951389/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:41:06  来源:igfitidea点击:

How to update embeded excel links in powerpoint 2010 using vba

excelexcel-vbahyperlinkpowerpointvba

提问by Dinesh Haraveer

My problem is i have pasted my charts into powerpointand I am trying to update the embedded links via Excel-VBA.

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

I have tried the codes below and failed:

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

code 1

代码 1

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

code 2

代码 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

code 3

代码 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

回答by Dinesh Haraveer

I have achieved it by spending some days trying on it

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

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

and BreakLines code

和 BreakLines 代码

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

回答by user8773481

Thank you! It worked once i was able to identify the object/chart#. (Click on an object, under Drawing Tools, Arrange, Selection Pane.) Here is my code. Now i can just run it and it instantly updates all my links. I didn't want to set it to auto-update because then when i send it out, the recipients get a warning message about links which is confusing. Thanks again.

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

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