Supercharge your PowerPoint productivity with
Supercharge your PPT Productivity with PPTools - Click here to learn more.

PPTools

Image Export converts PowerPoint slides to high-quality images.

PPT2HTML exports HTML even from PowerPoint 2010 and 2013, gives you full control of PowerPoint HTML output, helps meet Section 508 accessibility requirements

Merge Excel data into PowerPoint presentations to create certificates, awards presentations, personalized presentations and more

Resize your presentations quickly and without distortion

Language Selector switches the text in your presentation from one language to another

FixLinks prevents broken links when you distribute PowerPoint presentations

Shape Styles brings styles to PowerPoint. Apply complex formatting with a single click.

Prep4PDF preserves interactivity in PowerPoint presentations when you convert to PDF

Peekaboo Text: Use VBA to make text appear and disappear

Problem

You'd like to have text appear or disappear when you mouse over a shape.

The VBA macros below let you toggle the text in any shape on and off when you click or mouse over the shape.

Remember that VBA macros don't work in the free PowerPoint viewers or in web versions of PowerPoint presentations. If you need a non-VBA solution, see Sonia Coleman's Quick Tips (look for Tip #16)

Solution

Add the VBA subroutines below to your presentation (See How do I USE this VBA stuff in PowerPoint? if that sounds mysterious to you)

For each shape whose text you'd like to show/hide, give it a mouseclick or mouseover action setting of Run Macro: Peekaboo

Now start the slide show. When you click or mouse over the shape, the shape's text toggles on and off.

Peek-a-boo!

To reset the shapes so their text is invisible, run the show and trigger the action for each one where the text is visible. Or run the ResetPeekaboos macro below.

Sub Peekaboo(oSh As Shape)
' Hides/makes visible the shape's text

    With oSh.TextFrame.TextRange
        ' If it has text ...
        If Len(.Text) > 0 Then
            ' Store the text in a tag so we can retrieve it later
            oSh.Tags.Add "PeekabooText", .Text
            ' Now blank the text
            .Text = ""
        Else
            .Text = oSh.Tags("PeekabooText")
        End If
    End With

    ' Update: added this line to make it work in PPT 2007
    ' Leaving it in should not affect earlier versions of PPT
    SlideShowWindows(1).View.GotoSlide (oSh.Parent.SlideIndex)

End Sub

Sub ResetPeekaboos()
' Resets the shapes with peekaboo text to make the text invisible

    Dim oSh As Shape
    Dim oSl As Slide

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            If Len(oSh.Tags("PeekabooText")) > 0 Then
                oSh.TextFrame.TextRange.Text = ""
            End If
        Next    ' oSh
    Next    ' oSl

End Sub

Sub UnhidePeekaboos()
' Resets the shapes with peekaboo text to make the text visible

    Dim oSh As Shape
    Dim oSl As Slide

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            If Len(oSh.Tags("PeekabooText")) > 0 Then
                oSh.TextFrame.TextRange.Text = oSh.Tags("PeekabooText")
            End If
        Next    ' oSh
    Next    ' oSl

End Sub

Sub HidePeekaboos()
' Resets the shapes with peekaboo text to make the text invisible
' You must have activated the text as peekaboo one time for this to work

    Dim oSh As Shape
    Dim oSl As Slide

    For Each oSl In ActivePresentation.Slides
        For Each oSh In oSl.Shapes
            If Len(oSh.Tags("PeekabooText")) > 0 Then
                oSh.TextFrame.TextRange.Text = ""
            End If
        Next    ' oSh
    Next    ' oSl

End Sub

See How do I use VBA code in PowerPoint? to learn how to use this example code.

Search terms:


Did this solve your problem? If so, please consider supporting the PPT FAQ with a small PayPal donation.
Page copy protected against web site content infringement by Copyscape Contents © 1995 - 2015 Stephen Rindsberg, Rindsberg Photography, Inc. and members of the MS PowerPoint MVP team. You may link to this page but any form of unauthorized reproduction of this page's contents is expressly forbidden.
Español    Deutsch    Français    Português    Italiano    Nederlands    Greek    Japanese    Korean    Chinese

Supercharge your PPT Productivity with PPTools

content authoring & site maintenance by
Friday, the automatic faq maker (logo)
Friday - The Automatic FAQ Maker

Peekaboo Text: Use VBA to make text appear and disappear
http://www.pptfaq.com/FAQ00662_Peekaboo_Text-_Use_VBA_to_make_text_appear_and_disappear_.htm
Last update 07 June, 2011
Created: