Word WindowSelectionChanged event issue RRS feed

  • Question

  • Hi,

    Is it happening only to me!? The window_selectionchanged event in word is not firing when an object(chart, smartart) is deleted...

    i.e, click the object and delete(keyboard key) it

    is there any work around for this issue!?


    Balaji M

    Friday, March 28, 2014 9:00 PM

All replies

  • You're not alone - the WindowSelectionChange event is not triggered by deleting graphics, charts or smart-art. It is triggered by deleting auto-shapes and textboxes, though.

    However, since WindowSelectionChange will capture the selection of the chart or smart-art, you perhaps use something along the following lines:

    Dim x As Long, y As Long

    Private Sub wdApp_WindowSelectionChange(ByVal Sel As Selection)
    With ActiveDocument
      If Selection.Type = wdSelectionInlineShape Then
        x = .InlineShapes.Count
        y = .Range(0, Selection.InlineShapes(1).Range.End).InlineShapes.Count
      End If
      If .InlineShapes.Count < x Then
        MsgBox "Inline Shape " & y & " was deleted"
        x = .InlineShapes.Count
      End If
    End With
    End Sub

    The above code will report the deletion of an inlineshape upon the next change in selection. Additional code could be used to store the inlineshape's range, etc. The same principles can be applied to shape objects as well.

    Paul Edstein
    [MS MVP - Word]

    Saturday, March 29, 2014 5:41 AM
  • Thanks for the reply Paul!

    Yeah, this works for the next selection change, but the event doesnt trigger before u manually click somewhere after deleting...

    Guess there is no "correct" way we can catpture the change after a delete/cut

    Monday, March 31, 2014 2:30 PM