Changing the text in a shape during a slide show
Problem
You have shapes with numbers in them and want to let the user click the shape to increase/decrease the number, as might be useful when you're creating a game in PowerPoint.
Solution
Set each shape's Action Setting to Run Macro: MacroName
PowerPoint will then run the VBA subroutine called MacroName when you click on the shape during a slide show.
Note: Substitute any acceptable subroutine name for MacroName.
Mac PowerPoint has a few bugs that keep this trick from working as smoothly as it does in Windows PowerPoint but the code below works around these issues and works in either version of PowerPoint.
Sub IncrementNumber(oSh as Shape) Dim oSl as Slide Dim oShTemp as Shape ' oSh.Parent returns a valid reference to the shape's host slide: Set oSl = ActivePresentation.Slides(oSh.Parent.SlideIndex) ' oSh.Name works as well ' So we use those two bits to get a reference ' to the clicked shape like so Set oShTemp = oSl.Shapes(oSh.Name) With oShTemp .TextFrame.TextRange.Text = _ Cstr(CLng(oShTemp.TextRange.Text) + 1) End With End Sub
About this bit:
Cstr(CLng(oShTemp.TextRange.Text) + 1)
oShTemp.TextRange.Text gets the current text in the shape, Clng converts it from text to a number so we can do arithmetic on it, adds 1 to it, then Cstr converts it back to text so we can plug it back into the shape's text.
See How do I use VBA code in PowerPoint? to learn how to use this example code.