How to work with Message and Input Boxes in PowerPoint VBA?

Going through the comments, i have seen a couple of reader questions on how to work with Visual Basic Input and Message boxes in PowerPoint.

In this tutorial we’ll provide a very basic foundational knowledge to help you use those capabilities when automating your presentation creation.

Setting up the Developer Tab

First off, we’ll need to enable the developer environment for PowerPoint. Follow this tutorial to set up your development tab.

In PowerPoint, go to the Developer menu, and hit Visual Basic.

In the Project tree, right click your presentation, hit Insert and then pick Module. A new VBA Module will be created, that’s the place in which you’ll write your code.

Message Boxes in PowerPoint

Message boxes are kind of self explanatory, their goal is to display some useful information to the end user. Write the following code in your Module:

Sub simplemessagebox()
MsgBox ("This is a simple message box")
End Sub

Hit F5 or Run and see the result:

Message and Input Box example

Unlike Message Boxes, input boxes are used in order to obtain feedback from the user. Let’s look at the example below. The script automatically inserts new slides to the presentation.

Here’s what we’ll implement:

  1. We’ll first prompt the user for the number of slides to add (using an Input Box).
  2. We’ll then notify the user about the number of slides to be created (using a Message Box)
  3. Last, will go ahead and create the slides programmatically.
  4. Last we’ll save the modified presentation


Sub CreateSlidesMessage()

Dim NumSlides As Integer
Dim MsgResult As VbMsgBoxResult

' How many slides to create
NumSlides = InputBox("Enter number of slides to create", "Create Slides")

'User confirmation
MsgResult = MsgBox("Powerpoint will create " & NumSlides & " slides. Proceed?", vbApplicationModal, "Create Slides")

'create the slides
If MsgResult = vbOK Then
    For i = 1 To NumSlides
        Set NewSlide = ActivePresentation.Slides.Add(Index:=i + 1, Layout:=ppLayoutBlank)
    Next i
    'Save the Presentation
    ActivePresentation.SaveAs("Your Presentation.pptx")
    MsgBox ("Presentation Saved.")
End If

End Sub

Hopefully that helped, feel free to leave as comments as needed.