PowerPoint vba BeforeSaveAs

PowerPoint vba BeforeSaveAs,vba,powerpoint,powerpoint-automation,Vba,Powerpoint,Powerpoint Automation,我有一个PowerPoint模板,它与Excel链接。Excel中的某些区域已使用链接复制,因此将自动更新 无论何时将此PowerPoint模板另存为,我都需要删除这些指向外部Excel工作簿的链接 在PowerPoint中是否有这样做的方法 Private子工作簿\u保存前(ByVal SaveAsUI为布尔值,Cancel为布尔值)在Excel中 到目前为止 我尝试了下面提到的答案,没有任何运气。代码似乎没有运行-在这里我不知道我是否做错了。我试着在一个普通模块和一个类模块中运行它,但没有任

我有一个PowerPoint模板,它与Excel链接。Excel中的某些区域已使用链接复制,因此将自动更新

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

在PowerPoint中是否有这样做的方法

Private子工作簿\u保存前(ByVal SaveAsUI为布尔值,Cancel为布尔值)
在Excel中

到目前为止

我尝试了下面提到的答案,没有任何运气。代码似乎没有运行-在这里我不知道我是否做错了。我试着在一个普通模块和一个类模块中运行它,但没有任何方法让它发生。然后,我尝试将其作为普通sub运行,在这里,我在HasRevisionInfo
应用程序.PresentationBeforeSave上遇到了错误。

是的,请查看在保存演示文稿之前发生的错误。 下面是一个vb示例

是的,请在保存演示文稿之前查看发生的情况。 下面是一个vb示例


经过大量的研究,我得到了它的工作,@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
我选择在PowerPoint中制作一个“命令按钮”,让用户在查看演示文稿之前运行代码。然后,无论何时保存此演示文稿,用户都必须选择是否要删除链接:)


感谢您的帮助:)

经过大量研究后,我将其投入使用,@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
我选择在PowerPoint中制作一个“命令按钮”,让用户在查看演示文稿之前运行代码。然后,无论何时保存此演示文稿,用户都必须选择是否要删除链接:)


感谢您的帮助:)

感谢您的回复-但这不只是“保存”而不是“另存为”之前的解决方案吗。我需要模板保持完整,但如果用户选择“另存为”选项,它应该删除链接,因为它保存了模板的副本。我找到了这个解决方案,但我认为它会在演示文稿保存时执行,而不仅仅是保存为:)我会尝试一下,并尝试测试它。我无法让它工作-在执行此操作之前,我必须做些什么吗?有没有办法,我该怎么写?它应该在模块中还是在类模块中?我试图删除“If Pres.HasRevisionInfo Then”部分,并将其替换为“If Pres.Name=ActivePresentation.Name Then”-只是试图促使它发生-什么都没有发生,试图改变各种事情,仍然没有发生。我使用Office 2016(Office 365)和PowerPoint版本1912。这会影响它吗?另一个问题是,在PowerPoint VBA中,我不能使用ActivePresentation.HasRevisionInfo-为什么?我得到一个运行时错误“-2147188160(80048240)”:(Application.presentationbefore保存也是一个有效的选择。感谢您的回复-但这不只是“保存”而不是“另存为”之前的解决方案吗?我需要模板保持完整,但如果用户选择“另存为”选项它应该删除链接,因为它会保存模板的副本。我找到了这个解决方案,但我认为它会在保存演示文稿时执行,而不仅仅是保存为:)我会尝试一下,并尝试测试它。我无法让它工作-我必须做些什么才能执行此操作吗?有没有办法,我该怎么写?它应该在模块中还是在类模块中?我试图删除“If Pres.HasRevisionInfo Then”部分,并将其替换为“If Pres.Name=ActivePresentation.Name Then”-只是试图促使它发生-什么都没有发生,试图改变各种事情,仍然没有发生。我使用Office 2016(Office 365)和PowerPoint版本1912。这会影响它吗?另一个问题是,在PowerPoint VBA中,我不能使用ActivePresentation.HasRevisionInfo-为什么?我得到一个运行时错误“-2147188160(80048240)”:(Application.presentationbefore也不是有效选项。
Option Explicit
Dim cPPTObject As New cEventClass

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