Search code examples
vbaalignmentpowerpointselectionshapes

Detect if selected shape / table is in edit mode with VBA?


I'm trying to write a PowerPoint VBA macro that would act differently whether a shape is merely selected or is in edit mode (i.e. the cursor to edit the text is present, see image).enter image description here

Is there a way to check this using VBA in PowerPoint? I haven't been able to find on this anything so far

My ultimate goal being:

  • If just the shape is selected, the macro will align the shape left
  • If the shape is in edit mode, the macro will align the text left (and leave the shape where it is)

Any help would be appreciated Best


Solution

  • You can do this by using Selection.Type. If it returns 2, the shape is selected. If the insertion point is in the text, it will return 3:

    Sub DetectShapeOrText()
        MsgBox ActiveWindow.Selection.Type
    End Sub
    

    PpSelectionType enumeration (PowerPoint)