2

I have a PowerPoint template, which is links up with Excel. Some of the areas in Excel has been copied with links, so that it will automatically update.

Whenever this PowerPoint template will be Saved As, I need to remove these links to external Excel Workbooks.

Is there somehow to do this in PowerPoint just like

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

So far

I tried the below-mentioned answer, without any luck. The code somehow seems to not run - here I don't know if I'm doing it wrong. I tried running it in a normal module and a class module - without any way of provoking it to happen. Then I tried running it as a normal sub, and here I got errors on the HasRevisionInfoand alsoApplication.PresentationBeforeSave.

braX
  • 11,506
  • 5
  • 20
  • 33
Patrick S
  • 325
  • 2
  • 12

2 Answers2

0

Yes there is, look into Application.PresentationBeforeSave event which Occurs before a presentation is saved. Here is vb example

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
0m3r
  • 12,286
  • 15
  • 35
  • 71
  • Thank you for your response - But isn't this just a solution before it is "Saved" and not "Saved As". I need the template to stay intact, but if the user selects the option "Save As" it should delete the links, as it saves a copy of the template. I found this solution, but I thought that it would do it whenever the presentation is saved, and not just saved as :) I'll just give it a go, and try to test it. – Patrick S Jan 15 '20 at 10:43
  • I can't get this to work - do I have to do something before I can do this? Is there somehow a way, of how I should write it? Should it be in a Module or Class Module? I tried to remove the "If Pres.HasRevisionInfo Then" part, and replace it with "If Pres.Name = ActivePresentation.Name Then" - just trying to provoke it to happen - nothing happened, tried to change various things, still nothing. I use Office 2016 (Office 365) with the PowerPoint version 1912. Does that affect it somehow? – Patrick S Jan 16 '20 at 12:11
  • Another this is, that in PowerPoint VBA I cannot use ActivePresentation.HasRevisionInfo - why is that? I get a runtime error '-2147188160 (80048240)' :( Neither is Application.PresentationBeforeSave a valid choice. – Patrick S Jan 16 '20 at 12:19
0

I got it to work after a lot of research, @0m3R provided me with some of the right answer.

Somehow I found somewhere, that I had to combine a class module with a regular module.

Here's the code for the Class Module:

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

Here's the code for the regular Module

Option Explicit
Dim cPPTObject As New cEventClass

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

I chose to make a "Command Button" in my PowerPoint, to have the user run a code before viewing the presentation. Then whenever they will save this presentation, the have to choose if they want to delete the links or not :)

Thank you for your assistance :)

Patrick S
  • 325
  • 2
  • 12