2

我有一个与 Excel 链接的 PowerPoint 模板。Excel 中的某些区域已通过链接复制,以便自动更新。

每当将此 PowerPoint 模板另存为时,我都需要删除这些指向外部 Excel 工作簿的链接。

有没有办法在 PowerPoint 中做到这一点,就像

Private Sub Workbook_Before Save(ByVal SaveAsUI As Boolean, Cancel As Boolean)在 Excel 中?

至今

我尝试了下面提到的答案,但没有任何运气。代码似乎无法运行 - 在这里我不知道我是否做错了。我尝试在普通模块和类模块中运行它 - 没有任何方式引发它发生。然后我尝试将它作为普通子运行,在这里我在 HasRevisionInfo and alsoApplication.PresentationBeforeSave 上遇到错误。

4

2 回答 2

0

是的,请查看在保存演示文稿之前发生的Application.PresentationBeforeSave 事件。这是vb示例

Private Sub PPTApp_PresentationBeforeSave(ByVal Pres As Presentation, _
        Cancel As Boolean)

    Dim intResponse As Integer

    Set Pres = ActivePresentation

    If Pres.HasRevisionInfo Then

        intResponse = MsgBox(Prompt:="The presentation contains revisions. " & _
            "Do you want to accept the revisions before saving?", Buttons:=vbYesNo)

        If intResponse = vbYes Then

            Cancel = True

            MsgBox "Your presentation was not saved."

        End If

    End If

End Sub
于 2020-01-15T10:04:02.030 回答
0

经过大量研究后,我得到了它的工作,@0m3R 为我提供了一些正确的答案。

不知何故,我在某处发现,我必须将一个类模块与一个常规模块结合起来。

这是类模块的代码:

Private Sub PPTApp_PresentationBeforeSave(ByVal Pres As Presentation, Cancel As Boolean)
Dim sld As Slide
Dim shp As Shape
Dim TextValue As String
Dim intResponse As Integer

Set Pres = ActivePresentation

TextValue = "You're about to save this PowerPoint." & Chr(10) & "This Powerpoint is programmed to break all links" & _
" meaning that all of the content will not be updated automatically anymore." & Chr(10) & Chr(10) & _
"Do you wish to break all links?"

If Pres.Name <> "A3.potm" Then

intResponse = MsgBox(TextValue, Buttons:=vbYesNo)

If intResponse = vbYes Then
    For Each sld In Pres.Slides
        For Each shp In sld.Shapes
            On Error Resume Next
                shp.LinkFormat.BreakLink
            On Error GoTo 0
        Next shp
    Next sld
Else
MsgBox "You didn't break all links - the presentation may be overwritten in the future..."
End If
End If
End Sub

这是常规模块的代码

Option Explicit
Dim cPPTObject As New cEventClass

Sub InitializeApp()
    Set cPPTObject.PPTApp = Application
End Sub

我选择在我的 PowerPoint 中制作一个“命令按钮”,让用户在查看演示文稿之前运行代码。然后,每当他们保存此演示文稿时,都必须选择是否要删除链接:)

谢谢您的帮助 :)

于 2020-01-21T10:53:24.270 回答