dHumphrey
dHumphrey

Reputation: 307

Add text to powerpoint slide using vba

I have PowerPoint with a slide master set so all slides have same characteristics. I want to use VBA to place the SlideIndex number of the corresponding slide on each side.

As of now I have it so when you click a button, the slide index pops up in a message box but I want it to pop up in a text box or something on the slide itself.

Here is the script I am currently using..

Private Sub CommandButton_Click()

    MsgBox SlideShowWindows(1).View.Slide.SlideIndex

End Sub

I do not want to use a button. I want to automatically have it on each slide when its ran..Thanks in advance

Upvotes: 0

Views: 2569

Answers (2)

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

By the way, you don't need VBA for this.

Go to the slide master view. On the master, add a text box wherever you want the slide index to appear.

While you have the text insertion cursor active, choose: Insert | Slide Number

Upvotes: 0

Steve Rindsberg
Steve Rindsberg

Reputation: 14809

Add a text box to one slide. While it's selected, type this in the Immediate window to name it something meaningful to you:

ActiveWindow.Selection.ShapeRange(1).Name = "SlideNumber"

Then your button handling code can look like:

With SlideShowWindows(1).View.Slide.SlideIndex.Shapes("SlideNumber")
   .TextFrame.TextRange.Text = Cstr(SlideShowWindows(1).View.Slide.SlideIndex)
End with

Upvotes: 0

Related Questions