Others

Display a VBA String Array Element in a PowerPoint Text Shape

Natalie TaylorNatalie Taylor Nov 27, 2026 868 views

Question details

Display a selected VBA string array element in a PowerPoint text shape while a presentation is running.

Display a VBA String Array Element in a PowerPoint Text Shape
Product
Microsoft PowerPoint
Device & OS
not provided
Scenario
A presentation uses a VBA string array to store questions, and the user wants to show one question in a slide shape.
Observed behavior
The selected array value should appear as the text in the target shape during the slide show.
Before you start

Check that the target slide and shape exist and that the shape can contain text. Save the presentation as a macro-enabled PowerPoint presentation (.pptm), and allow macros only if you trust the file.

Solution 1Recommended

Assign the Array Element to the Shape's Text Range

Use VBA to set the target shape's text to the selected string, then run the macro during the slide show.

1
Open the VBA editor

In PowerPoint, open the Developer tab and select Visual Basic. In the editor, choose Insert > Module.

2
Add the macro

Paste this example into the module: Sub ShowQuestion() Dim sQuestions(1 To 2) As String sQuestions(1) = "What is your question?" sQuestions(2) = "What is your next question?" ActivePresentation.Slides(3).Shapes(7).TextFrame.TextRange.Text = sQuestions(1) End Sub Replace the sample strings and slide and shape indexes with your own. If your array is already populated elsewhere, use its selected element in the assignment instead.

3
Connect a slide-show action

On a slide, select a button or shape, choose Insert > Action, and set its click action to Run macro > ShowQuestion.

4
Run the slide show

Start the presentation from Slide Show and click the assigned button. The macro writes the selected array value to shape 7 on slide 3; navigate to slide 3 to see it.

Assign the Array Element to the Shape's Text Range
Check the array and shape indexes: The example explicitly starts the array at 1, so sQuestions(1) is its first element. Other arrays may start at 0 or another index. Shape indexes can also change when shapes are added or removed.
Free Microsoft Office alternative

Edit PowerPoint Slides with WPS Presentation

WPS Office is a free, lightweight alternative with a familiar interface for editing presentations and moving between Office files. It does not fix PowerPoint VBA issues, and macro compatibility can vary.

Add and edit text in slide shapes with WPS PresentationOpen and edit Microsoft PowerPoint PPT and PPTX filesUse a familiar interface for a smoother transition from Microsoft OfficeWork with a lightweight office suite with free features
microsoft office alternative - wps office

Frequently Asked Questions

How do I display an array element in a PowerPoint shape?

In VBA, assign the element to the shape's text range, for example: ActivePresentation.Slides(3).Shapes(7).TextFrame.TextRange.Text = sQuestions(1). Make sure the indexes identify an existing slide, text-capable shape, and array element.

Is sQuestions(1) always the first array element?

No. It is the first element only if the array's lower bound is 1. Use LBound(sQuestions) to check the lower bound of an initialized array.

Can I refer to the shape by name instead of its index?

Yes. For example, use ActivePresentation.Slides(3).Shapes("QuestionBox").TextFrame.TextRange.Text = sQuestions(1). You can inspect or rename shapes in PowerPoint's Selection Pane.

How can I run the macro during a slide show?

Select a button or shape, open Insert > Action, and assign the macro under Run macro. Start the slide show and click the button. The file must permit the macro to run.

Why is the Run macro action unavailable?

Check that the presentation is saved as a .pptm file and that the macro is a public, parameterless Sub in a standard module. Also check PowerPoint's macro security settings and enable macros only for trusted files.