Search code examples
vbapowerpointselectionshapes

Is there a way to determine if the user selected a shape or a table with PowerPoint VBA?


I'm trying to write a PowerPoint macro that would act differently whether the user has selected a PowerPoint table or a "classic" shape (textbox, etc.).

Is there a way to check this with a condition in VBA ?

I've found workarounds using error handling, but I guess there is a proper way to do it.

Any help appreciated Thanks!


Solution

  • Like so:

    Sub TableOrShape()
        If ActiveWindow.Selection.ShapeRange(1).HasTable Then
            MsgBox "It's a table!"
        ElseIf ActiveWindow.Selection.ShapeRange(1).HasTextFrame Then
            MsgBox "It's a text box!"
        End If
    End Sub