How to automate to insert the document title in each slide of the powerpoint presentation using VBA

I had this question after viewing Replacing text in PowerPoint 2016 using VBA.

Is it possible that I can insert a custom textbox in slide theme and it gets updated in actual slides ?
Here what I am trying to do in power point VBA which I have done successfully in Visio VBA.

I want to put the presentation file name on all slides of a presentation.  I have 50+ such presentations containing 25+ slides in each presentation.  The above code requires that I insert a text box on each of the slide manually and then it works if I run the macro.  Any suggestion how to automate the process using Powerpoint VBA ?

I do not want to change the slides theme for each presentation by inserting a text box with file name.  That would defeat the purpose of automation. Visio VBA does it very easily by using code in Auotexec module for each slidepack.
Suresh AgrawalPresidentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jamie GarrochSenior Technical Consultant at BrightCarbonCommented:
You could simplify the process as follows:

1. Open the slide master "parent" by holding the Shift key and double-clicking the Normal view icon in the bottom right hand half of the status bar in PowerPoint.
2. Insert a text box into the parent slide of the master.
3. With the text box selected, insert the following macro (Alt+F11) and run it (Alt+F8)

' PowerPoint VBA Macro
' Author : Jamie Garroch of BrightCarbon (
' Date : 16JAN2019
' Purpose : insert the current presentation's file name into the selected shape
Sub InsertFileNameIntoSelectedShape()
  On Error GoTo errorhandler
  With ActiveWindow.Selection
    If .Type = ppSelectionShapes Or .Type = ppSelectionText Then
      With ActiveWindow.Selection.ShapeRange(1)
        If .HasTextFrame Then
          .TextFrame.TextRange.Text = ActivePresentation.Name ' or .FullName if path required
          GoTo quit
        End If
      End With
      GoTo quit
    End If
  End With
Exit Sub

  MsgBox "Select a shape that supprts text.", vbCritical + vbOKOnly, "Invalid Selection"
Exit Sub

  MsgBox "Error :" & Err & vbCrLf & vbCrLf & Err.Description, vbCritical + vbOKOnly, "Unhandled Error"

End Sub

Open in new window

Suresh AgrawalPresidentAuthor Commented:
Hi Jamie,

Your code works. I was just wondering if the textbox (shape) in the parent slide of the master can be given a fixed name and referred to that name in the code. So that we don't have to open the master for new presentation and run this manually. Anytime a new presentation is opened, the master will update the presentation name automatically in the text box.  This code then can possibly  be run in autoexec module in ppt VBA ?


Suresh Agrawal
Suresh AgrawalPresidentAuthor Commented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Visio

From novice to tech pro — start learning today.