Home | VBA Section | General Section | Downloads | Licensing | Privacy Policy

Roll Over Demonstration

It is often asked if a roll over effect can be done in PowerPoint such that when the user moves the mouse over a shape during the slide show, a message is displayed on another section of the slide dynamically. This is can be easily achieved with some ingenuity and some VBA. Let use take a look how by creating a demo which does this exactly.

  Download

  • Create a Slide which follows the layout as shown in the diagram below. The numbers mentioned in the diagram correspond to the index values of the shapes on the slides which will be used in the code. Set the action settings of all shapes index 1 to 8 to run the macro given below. Shape with index value 8 is the designated shape which will display the text message on mouse roll over.


     

  • Insert a code module in the VBA project and paste the code given below. We shall make use of this article to ascertain the shape over which the mouse has moved.  Whenever the mouse cursor moves over a shape, this macro will be invoked and depending upon the index of the shape, an appropriate message will be displayed by changing the text in the designated shape
     

    Option Explicit
    Sub DisplayMessage(oShp As Shape)
    ' Ascertain the position of the mouse by checking the
    ' index value of shape over which the mouse rests.
        With SlideShowWindows(1).View.Slide _
             .Shapes(8).TextFrame.TextRange
            Select Case oShp.ZOrderPosition
        ' The purple rectangle on which the buttons rest
        ' we use the event here to clear the existing message while
        ' the mouse moves to the next shape
            Case 1
                .Text = ""
            Case 2
                .Text = "Descriptive Message when mouse moves over Shape 2"
            Case 3
                .Text = "Descriptive Message when mouse moves over Shape 3"
            Case 4
                .Text = "Descriptive Message when mouse moves over Shape 4"
            Case 5
                .Text = "Descriptive Message when mouse moves over Shape 5"
            Case 6
                .Text = "Descriptive Message when mouse moves over Shape 6"
            Case 7
                .Text = "Descriptive Message when mouse moves over Shape 7"
            Case 8
                .Text = "Descriptive Message when mouse moves over Shape 8"
            End Select
            DoEvents
        End With
    End Sub
  • Ensure that all the shapes have their mouse over action setting set to run the macro DisplayMessage.
  • Run the show and trying moving the mouse cursor over various shapes.

Copyright © 1999-2008 Shyam Pillai. All rights reserved.