Consulting

Results 1 to 3 of 3

Thread: How to select a specific Textbox in a powerpoint slide with user selection

  1. #1
    VBAX Regular
    Joined
    Sep 2018
    Posts
    14
    Location

    How to select a specific Textbox in a powerpoint slide with user selection

    Hello Everyone,

    Is it possible to allow user to select a specific textbox using VBA and get word-count of that textbox?

    thanks

  2. #2
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,234
    Location
    Maybe this will give you some ideas.
    Option Explicit
     
     Sub CountSomeWords()
    ' Example of how to use WordsOnSlide
    Dim oSl As Slide
    Dim lWordCount As Long
    For Each oSl In ActivePresentation.Slides
     lWordCount = lWordCount + WordsOnSlide(oSl)
    Next
    MsgBox lWordCount
    End Sub
     
     Function WordsOnSlide(oSl As Slide) As Long
    ' Gives APPROXIMATE word count of the words in
    ' text boxes and normal shapes on a slide
    ' Does not count shapes in groups, text in charts
    ' smart art, graphics, etc.
    Dim oSh As Shape
    Dim lCount As Long
    For Each oSh In oSl.Shapes
     If oSh.HasTextFrame Then
     If oSh.TextFrame.HasText Then
     lCount = lCount + oSh.TextFrame.TextRange.Words.Count
    End If
     End If
    Next
    WordsOnSlide = lCount
    End Function
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

  3. #3
    VBAX Newbie
    Joined
    Jul 2024
    Posts
    1
    Location
    Quote Originally Posted by Aussiebear View Post
    Maybe this will give you some ideas.
    Option Explicit
     
     Sub CountSomeWords()
    ' Example of how to use WordsOnSlide
    Dim oSl As Slide
    Dim lWordCount As Long
    For Each oSl In ActivePresentation.Slides
     lWordCount = lWordCount + WordsOnSlide(oSl)
    Next
    MsgBox lWordCount
    End Sub
     
     Function WordsOnSlide(oSl As Slide) As Long
    ' Gives APPROXIMATE word count of the words in
    ' text boxes and normal shapes on a slide
    ' Does not count shapes in groups, text in charts
    ' smart art, graphics, etc.
    Dim oSh As Shape
    Dim lCount As Long
    For Each oSh In oSl.Shapes
     If oSh.HasTextFrame Then
     If oSh.TextFrame.HasText Then
     lCount = lCount + oSh.TextFrame.TextRange.Words.Count
    End If
     End If
    Next
    WordsOnSlide = lCount
    End Function

    Thanks. I know what I have to do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •