Share via

PowerPoint possible bug VBA

Anonymous
2017-07-04T09:11:59+00:00

Eventsub WindowSelectionChange(ByVal Sel As Selection)

Error accessing a NotesPage

Selecting a NotesPage Sel/ActiveWindow.Selection has no ShapeRange. This obviously a bug? A Textrange needs a hosting Shape.

Work a round:

If TextRange has no Parent (Shape) I guess Sel is selecting the Notespage

Private Sub App_WindowSelectionChange(ByVal Sel As Selection)

If Sel.Type = ppSelectionText Then

If Sel.TextRange.Parent Is Nothing And Sel.SlideRange.HasNotesPage Then

    Application.Caption = "Word.Count( NotesPage )= " & Sel.SlideRange.NotesPage.Shapes.Placeholders(ppPlaceholderBody).TextFrame.TextRange.Words.Count

  Else

    Application.Caption = "Word.Count( " & Sel.ShapeRange(1).Name & " )= " & Sel.ShapeRange(1).TextFrame.TextRange.Words.Count

  End If

End If

End Sub

Microsoft 365 and Office | PowerPoint | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

7 answers

Sort by: Most helpful
  1. Anonymous
    2017-07-05T16:30:36+00:00

    This code runs oK for me when I select a text placeholder on the notes page -are you sure you have initialized the event>

    Public WithEvents EV As Application

    Private Sub EV_WindowSelectionChange(ByVal Sel As Selection)

    If Sel.Type = ppSelectionText Then

    Debug.Print Sel.TextRange.Parent.Parent.Name

    Application.Caption = Sel.TextRange.Parent.Parent.Name

    End If

    End Sub

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2017-07-05T11:46:37+00:00

    No, the Selection is in a Notespage:

    Sel.SlideRange.NotesPage.Shapes.Placeholders(ppPlaceholderBody).TextFrame.TextRange.Text

    no table in Selection

    BTW:  Thank you for sharing your knowledge of ms office and follow through this thread.

    I found this problem making a video to handle an eventclass

    https://youtu.be/zVVIuYp\_esQ

    Was this answer helpful?

    0 comments No comments
  3. Steve Rindsberg 99,166 Reputation points MVP Volunteer Moderator
    2017-07-05T10:47:09+00:00

    Is the current text selection part of a table?  In that case, yes, it's a known bug.  The .Parent chain in selected table text is broken.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2017-07-04T17:55:09+00:00

    You are right. But this case does go wrong.  This is why I assume a bug..

    Selection is in NotesPage

    ShapeRange ist not valid

    TextRange Parent is nothing

    Was this answer helpful?

    0 comments No comments
  5. Steve Rindsberg 99,166 Reputation points MVP Volunteer Moderator
    2017-07-04T16:47:05+00:00

    The Parent of a TextRange isn't a slide, it's a TextFrame.

    To get the parent shape, use TextRange.Parent.Parent

    To get the parent slide, us TextRange.Parent.Parent.Parent

    Unless the selected text is part of a table; in that case, set your hair on fire and run screaming into the weeds.  Tables are buggy.

    Was this answer helpful?

    0 comments No comments