Share via

PowerPoint: creating first BeforeSave macro

Anonymous
2018-11-19T12:44:20+00:00

Hi,

I have found a macro online (here) which I want to use whenever someone save's a presentation. I understand I need to put this into an add-in. 

I have read various topics on this, including this, but I am utterly confused about what code to put where and how to create the BeforeSave event. I have very limited VBA knowledge so some hand-holding would be appreciated.

Can someone help and provide an idiots step-by-step?

Thanks in advance. I am using PowerPoint 2010.

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Anonymous
    2018-11-20T15:15:52+00:00

    @John SR Wilson, thanks. I was using whatever Steve recommended I use. However, I have just tried your suggestion, which now looks like this

    I trust I have everything in the right place?

    When I save this as a *.ppam and load as an add-in, I don't get any message boxes when saving or saving as. Before, using Steve's code, I got a "hello" prompt after saving, but only when selecting pptx as the file format. The "hello" never appeared if I changed the file format to PDF then pressed save.

    Hope this makes sense.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2018-11-20T14:31:50+00:00

    Did you use the Save event or the BeforeSave event? the latter might be what you need.

    Private Sub EV_PresentationBeforeSave(ByVal Pres As Presentation, Cancel As Boolean)

    Call killAlttext(Pres)

    End Sub

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2018-11-20T12:53:56+00:00

    Hello both,

    Thanks for the replies - much appreciated.

    To give some background on this, the reason we want to use a macro like this is we generate lots of client presentations using photos from our portfolio of work and typically save a copy of the presentation as PDF. You are probably aware that when importing photos from a network drive, the AltText of the photo automatically shows the original file path in the PDF version. 

    We have in the past presented to clients (an example being be Coca-Cola*) where we have used images from our work with Pepsi*. We don't want "\work\clients\pepsi\design1.jpeg" showing as the AltText tooltip when hovering over a photo. This has happened a few times and is a costly mistake for our company.

    * Not actual clients of ours ;-)

    There are two ways we know of dealing with this; either blank out the AltText, or turn off 'document structure tags' when saving as PDF.

    We had created a custom button, and added to the toolbar, to allow users to click, which ran a macro to save the current presentation in PDF with the document structure tags turned off. However, lots of colleagues are forgetting/ignoring to do this so we would like to build-in something foolproof. Hence the original question.

    Thanks for Steve for the excellent guide to creating the add-in. It worked well. I actually changed the macro code to "msgbox "hello"" to get a visual indication of this working. However, I noticed it only showed this message box when the document was saved as PPTX format and never when changing the drop down to PDF. I'm guessing this is because there is some in-built code that actually prints the presentation to PDF, rather than saving, so perhaps this whole idea isn't possible with BeforeSave (or even BeforeSaveAs).

    Is there another way to tackle this and ensure that all PDF's are created either with blanked AltText's or document structure tags unchecked?

    Thanks very much in advance.

    Was this answer helpful?

    0 comments No comments
  4. Steve Rindsberg 99,166 Reputation points MVP Volunteer Moderator
    2018-11-19T17:10:13+00:00

    If you only need this to happen once or periodically to presentations you're working on, John's correct, no need for an add-in.  If you need the code to run whenever you or someone else saves an edited file, an add-in will be needed.

    What follows is a modifed/simplified version of Shyam Pillai's example file Event Handler Demo in PowerPoint 2000+

    http://www.skphub.com/download.htm

    Add a class module to your project and name it cEventClass

    Paste this code into it:

    Option Explicit

    Public WithEvents PPTEvent As Application

    Private Sub PPTEvent_PresentationSave(ByVal Pres As Presentation)

        Call Handle_SaveEvent

    End Sub

    Add a regular module and paste this into it:

    Dim cPPTObject As New cEventClass

    Sub Auto_Open()

        Set cPPTObject.PPTEvent = Application

    End Sub

    Sub Handle_SaveEvent()

        ' add whatever code you like here

        ' it should run when you save a presentation

    End Sub

    Add whatever code you like to the Handle_SaveEvent sub. 

    Save it as an add-in, load the add-in and test.

    All of the above is somewhat "air code".  It should work, or close to it, though.

    Was this answer helpful?

    0 comments No comments
  5. John Korchok 232.8K Reputation points Volunteer Moderator
    2018-11-19T15:25:17+00:00

    It's seems like overkill to run that macro every time you save. You really just need to run it once when the presentation is final. Please try creating a new blank presentation, then saving it as a .pptm macro-enabled presentation. Write your macro and debug it in the .pptm file. Save it somewhere easy to find.

    When you want to run the macro to delete Alt text:

    1. Open the presentation with the macro, then switch back to the presentation being prepared.
    2. Choose Developer>Macros.
    3. Change the Macro in: dropdown to show the .pptm file.
    4. Click on the macro name and click on Run.
    5. Save the presentation that has has the Alt text removed.

    This approach is less frustrating to get up and running, and the code is more easily editable if you need to update your macro. I keep a .pptm file packed with little utilities and use it this way for occasional tasks.

    Was this answer helpful?

    0 comments No comments