none
Powerpoint VBA Shapes onFocus RRS feed

  • Question

  • hello gurus, on a slide if shapes are place.

    Like in a particular slide, there is circle, rectangle, or square.

    Is it possible to have controls on these shapes  via VBA?

    Like if the focus is on the Circle, there will be a message that will pop up like "This is a circle".

    Is it possible to do this?

    Thanks for any input.


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Wednesday, March 5, 2014 4:17 AM

Answers

  • Hello cguan,

    Yes, it is possible. You just need to handle the WindowSelectionChange event of the Application class. It occurs when the selection of text, a shape, or a slide in the active document window changes, whether in the user interface or in code. MSDN provides the following sample code in VBA:

    Private Sub App_WindowSelectionChange(ByVal Sel As Selection)
        With Sel
            If .Type = ppSelectionNone Then
                With .SlideRange(1)
                    .ColorScheme.Colors(ppBackground).RGB = _
                        RGB(240, 115, 100)
                End With
            End If
        End With
    End Sub
    

    Note, the Selection object is passed an argument to the event handler. The example determines when a different slide is being selected and changes the background color of the newly selected slide.

    • Marked as answer by cguan Friday, March 7, 2014 8:27 AM
    Wednesday, March 5, 2014 1:30 PM
  • Hi cguan,

    First of all, I'd recommend asking separate questions in new forum threads. Thus, forum readers may recognize answers easily.

    The Item method of the Shapes class allows you to get the Shape object by its name, not only index.

    ActivePresentation.Slides.Item(1).Shapes.Item("rectangle 1")

    Here is what MSDN states for this:

    When a shape is created, Microsoft PowerPoint automatically assigns it a name in the form ShapeType Number, where ShapeType identifies the type of shape or AutoShape, and Number is an integer that's unique within the collection of shapes on the slide. For example, the automatically generated names of the shapes on a slide could be Placeholder 1, Oval 2, and Rectangle 3.

    • Marked as answer by cguan Friday, March 7, 2014 8:27 AM
    Thursday, March 6, 2014 9:30 PM
  • Hi Eugene, Thank you for pointing out to the MSDN.

    I found this one:

    With ActivePresentation.Slides(1).Shapes(3) _ .ActionSettings(ppMouseOver) .Action = ppActionRunMacro .Run = "CalculateTotal" .AnimateAction = True End With

    from this link:

    http://msdn.microsoft.com/en-us/library/office/aa220868(v=office.11).aspx

    but i have another question, i know that the first shape you add will

    have a reference of 1 and the next shape you add will have a reference of 2

    and number reference will continue ..

    but what if you forget which shape you added first.

    Is there a way to check what reference number the shape is holding on?

    Thanks again.


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    • Marked as answer by cguan Friday, March 7, 2014 8:27 AM
    Thursday, March 6, 2014 9:18 PM

All replies

  • Hello cguan,

    Yes, it is possible. You just need to handle the WindowSelectionChange event of the Application class. It occurs when the selection of text, a shape, or a slide in the active document window changes, whether in the user interface or in code. MSDN provides the following sample code in VBA:

    Private Sub App_WindowSelectionChange(ByVal Sel As Selection)
        With Sel
            If .Type = ppSelectionNone Then
                With .SlideRange(1)
                    .ColorScheme.Colors(ppBackground).RGB = _
                        RGB(240, 115, 100)
                End With
            End If
        End With
    End Sub
    

    Note, the Selection object is passed an argument to the event handler. The example determines when a different slide is being selected and changes the background color of the newly selected slide.

    • Marked as answer by cguan Friday, March 7, 2014 8:27 AM
    Wednesday, March 5, 2014 1:30 PM
  • Thanks Eugene, will try it out. 

    Keep you posted.


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Wednesday, March 5, 2014 2:18 PM
  • Hi Eugene, Thank you for pointing out to the MSDN.

    I found this one:

    With ActivePresentation.Slides(1).Shapes(3) _ .ActionSettings(ppMouseOver) .Action = ppActionRunMacro .Run = "CalculateTotal" .AnimateAction = True End With

    from this link:

    http://msdn.microsoft.com/en-us/library/office/aa220868(v=office.11).aspx

    but i have another question, i know that the first shape you add will

    have a reference of 1 and the next shape you add will have a reference of 2

    and number reference will continue ..

    but what if you forget which shape you added first.

    Is there a way to check what reference number the shape is holding on?

    Thanks again.


    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    • Marked as answer by cguan Friday, March 7, 2014 8:27 AM
    Thursday, March 6, 2014 9:18 PM
  • Hi cguan,

    First of all, I'd recommend asking separate questions in new forum threads. Thus, forum readers may recognize answers easily.

    The Item method of the Shapes class allows you to get the Shape object by its name, not only index.

    ActivePresentation.Slides.Item(1).Shapes.Item("rectangle 1")

    Here is what MSDN states for this:

    When a shape is created, Microsoft PowerPoint automatically assigns it a name in the form ShapeType Number, where ShapeType identifies the type of shape or AutoShape, and Number is an integer that's unique within the collection of shapes on the slide. For example, the automatically generated names of the shapes on a slide could be Placeholder 1, Oval 2, and Rectangle 3.

    • Marked as answer by cguan Friday, March 7, 2014 8:27 AM
    Thursday, March 6, 2014 9:30 PM
  • Thanks Eugene :)

    Every second counts..make use of it. Disclaimer: This posting is provided AS IS with no warranties or guarantees and confers no rights.

    Friday, March 7, 2014 8:27 AM