How to Use VBA to Add Text To PowerPoint Slides

This article explains how you can add text to PowerPoint slides using VBA.

Note unlike MS Word where you can add text anywhere in the document, in PowerPoint you can only add text inside text boxes. This is regardless of whether you are using VBA or you are trying to manually input text. So the first thing we need is a text box. Most slide templates come with preset text boxes. Although there are a few that don’t have any text boxes at all. In this article I will assume that there is already a textbox available in the slide and we will fill the textbox with text.

In the figure below you can see an empty slide. It has 2 textboxes:
Textboxes
Previously I have explained how to access slide objects. If you look at the presentation you will see that the slide has an index of “2”:
2

The code below will return a reference to the slide object:

Dim objPresentaion As Presentation
Dim objSlide As Slide

Set objPresentaion = ActivePresentation
Set objSlide = objPresentaion.Slides.Item(2)

Textboxes, pictures, smartart, video files, … they are all considered shapes in the slide. We have 2 textboxes in the selected slide, therefore there will be 2 shape objects in the slide. We can get reference to the textbox object using the code below:

Dim objPresentaion As Presentation
Dim objSlide As Slide
Dim objTextBox As Shape

Set objPresentaion = ActivePresentation
Set objSlide = objPresentaion.Slides.Item(2)
Set objTextBox = objSlide.Shapes.Item(2)

In order to write text in the textbox we can use the code below:

Dim objPresentaion As Presentation
Dim objSlide As Slide
Dim objTextBox As Shape

Set objPresentaion = ActivePresentation
Set objSlide = objPresentaion.Slides.Item(2)
Set objTextBox = objSlide.Shapes.Item(2)

objTextBox.TextFrame.TextRange.Text = "Some Text"

Result:
Result

One thought on “How to Use VBA to Add Text To PowerPoint Slides”

  1. Max says:

    Where is the code for case 2 and 3??

Leave a Reply

Your email address will not be published. Required fields are marked *

privacy policy