Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Run VBA after Presentation in PowerPoint Opens

Run VBA after Presentation in PowerPoint Opens

Run VBA after Presentation in PowerPoint Opens

It's been a while since I have had to code something in PowerPoint (as in over 4 years) and things have changed a bit. I would like a piece of code to run when the presentation is done opening.

We have slides that get uploaded to a file documentation system and when they do, it changes whatever the file name is to the Document Number and Version. If someone downloads to their machine, we want to replace the Rev # with the document title so it's all consistent. I can run the OnLoadCode manually and it does what I expect. How in Powerpoint can this happen with a mouse motion, on load, etc?

Any help is appreciated.

CODE --> vba

Public App As Application
Private Sub App_AfterPresentationOpen(ByVal Pres As Presentation)
    With Pres
    End With

End Sub

'Sub Auto_open()
 '   OnLoadCode
'End Sub

Sub OnLoadCode()
    Dim sld As Slide
    Dim shp As Shape
    Dim fileName As String
    Set sld = ActivePresentation.Slides(1)
    fileName = Replace(Application.ActivePresentation.Name, ".pptm", "")
    'MsgBox fileName
    For Each shp In sld.Shapes
        If shp.HasTextFrame Then
            If shp.TextFrame.HasText Then
                shp.TextFrame.TextRange.Text = Replace(shp.TextFrame.TextRange.Text, "1", fileName)
            End If
        End If
    Next shp
End Sub 

RE: Run VBA after Presentation in PowerPoint Opens

First, you need to make powerpoint to run initial macro. This can be done in powerpoint add-in with Auto_Open procedure, it does not work for regular presentations. This add-in has to have class module that has a public application variable declared with WithEvents and selected application events procedure. Auto-Open procedure should instantiate the class and assign application to the variable declared with WithEvents.

Having this, you will pick all presentations that powerpoint opena, as long as the add-in is installed


RE: Run VBA after Presentation in PowerPoint Opens

I have never had to make an addin - I tried yesterday for about 3 hours and had no luck. Any hints, clues, help on how to do this. BTW I have Microsoft 365.

RE: Run VBA after Presentation in PowerPoint Opens

You have to save presentation as powerpoint add-in type (.ppam). Powerpoint suggests folder for add-ins. Add-ins can be open or not when powerpoint starts, this is set either in options settings or in developer tab, both for powerpoint add-ins type.


RE: Run VBA after Presentation in PowerPoint Opens

I have it saved as a .ppam and it is going to an AppData folder on the C: but it is not running any code on open.

RE: Run VBA after Presentation in PowerPoint Opens

Do you have Auto_Open procedure in the add-in? Is the add-in turned on? Try to insert MsgBox in the procedure, you will be sure that the code runs.


RE: Run VBA after Presentation in PowerPoint Opens

I can insert a button and run the code no problem. It's just trying to get an add in to work. I don't think this can be a permanent solution - I'd have to install the stupid add in on every machine in order to make it run. Sometimes Microsoft just gets it wrong.

RE: Run VBA after Presentation in PowerPoint Opens

There are workarounds ... whether you consider them more or less convoluted than creating and distributing an add-in is going to be down to personal preference, however

For example, with a little cunning, you can respond to the presentations Ribbon opening (assuming you are using a version of Powerpoint with the Ribbon interface), by adding some custonmUI XML (which needs an offcie custom UI XML ediror; the one I use is found here, but there are others, including an MS version

All it takes is

1 Add a module to your presentation
2 Add the following code:

CODE -->

Option Explicit

Public Sub onLoadRibbon(myRibbon As IRibbonUI)
  ' Add your code here
  Example ' just an example
End Sub

Public Sub Example()
    MsgBox ActivePresentation.Name & " has " & ActivePresentation.Slides.Count & " slides"
End Sub 

3. Save and close your presentation
4. Open presentation in Custom UI editor
5. Add the following highly complex UI customisation:

CODE -->

<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui"
onLoad="onLoadRibbon" ></customUI> 

6. Save it.

All done

Opening your presentation in Powerpoint will trigger the UI's OnLoad event, which in turn now triggers your onLoadRibbon code

RE: Run VBA after Presentation in PowerPoint Opens

Finally - easier that I thought. I was able to make the add-in and auto run - we will just have to have 2 engineers run. Thank you

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close