PDA

View Full Version : Checking number of words in a sentence



mattvb
10-14-2016, 06:09 PM
Hi,

I'm wondering if it is possible to check the number of words in a sentence in PowerPoint?

I'm using this code to do so in Word and would like to do the same in PowerPoint, but from what I've read this may not be possible:



Sub HighlightLongSentences()
Dim oSent As Range
Dim Count As Integer
Dim Words As Integer
Count = 0
Words = 20
For Each oSent In ActiveDocument.Sentences
If oSent.ComputeStatistics(wdStatisticWords) > Words Then
oSent.HighlightColorIndex = wdYellow
Count = Count + 1
End If
Next
MsgBox "This document contains " & Count & " sentence/s that have more than " & _
Words & " words."
End Sub


I tried using the 'Create Handouts > Outline Only' option in PowerPoint to get the text into a word document, but this only grabs text that from placeholders.

So... two questions:

1. Is there a way to get all text (e.g. from placeholders, text boxes, shapes, notes etc) and export it to Word?

2. Or a way to highlight sentences in PowerPoint that are over a certain length?

Thanks,
Matt

John Wilson
10-15-2016, 07:08 AM
Only the very latest version of subscription 365 can highlight and even then the vba is buggy. You might need to underline or something else. Be careful becuase in some earlier versions it can be difficult to UNHighlight. Work on a copy always.


Sub HighlightLongSentences()
Dim L As Long
Dim W As Long
Dim sngSize As Single
Dim otr2 As TextRange2
Dim intCount As Integer
Const intWords As Integer=20


Dim osld As Slide
Dim oshp As Shape
For Each osld In ActivePresentation.Slides
For Each oshp In osld.Shapes
If oshp.HasTextFrame Then
If oshp.TextFrame2.HasText Then
Set otr2 = oshp.TextFrame2.TextRange
For L = 1 To otr2.Sentences.Count
If otr2.Sentences(L).Words.Count > intWords Then
sngSize = otr2.Sentences(L).Font.Size
otr2.Sentences(L).Font.Highlight.RGB = vbYellow
otr2.Sentences(L).Font.Size = sngSize
intCount = intCount + 1
End If
Next L
End If
End If
Next oshp
Next osld
MsgBox "This document contains " & intCount & " sentence/s that have more than " & _
intWords & " words."
End Sub




See here for send to word code (scroll down)

http://www.pptalchemy.co.uk/PPT2WORD.html

mattvb
10-15-2016, 08:04 AM
That's wonderful, thanks John. I really appreciate your help with this.

If I wanted to unhighlight sentences that are < intWords, how would I do that?

The send to word code is great, especially the Outline and Notes bit which seems to send all of the text (including notes) to Word. Thanks again.

John Wilson
10-15-2016, 08:38 AM
"Be careful becuase in some earlier versions it can be difficult to UNHighlight"

To the best of my knowledge you can only unhighlight manually (not in code) if you have the latest version. In earlier versions it is a matter of using the format painter.

mattvb
10-15-2016, 08:43 AM
Okay, thanks John. All the best.

rtpathy
10-17-2016, 01:10 AM
Here is a sample value of a cell that contains my data

"Z_DRAWING_NUMBER : SP2422-B50-NA2101-601&602-005 ; Z_TAG_NUMBER : B50-MS1-XFR(T)-206 ; Z_TAG_NUMBER : B50-MS1-XFR(T)-205 ; Z_TAG_NUMBER : B50-MS1-XFR(T)-204 ; Z_SERIAL_NUMBER : JD85087203 - 6 ; Z_SERIAL_NUMBER : JD85087203 - 5 ; Z_SERIAL_NUMBER : JD85087203 - 4 ; Z_SERIAL_NUMBER : JD85087203 - 3 ; Z_SERIAL_NUMBER : JD85087203 - 2 ; Z_SERIAL_NUMBER : JD85087203 - 1 ; Z_MODEL_NUMBER : JD85087203 ; Z_TAG_NUMBER : B50-MS1-XFR(T)-203 ; Z_TAG_NUMBER : B50-MS1-XFR(T)-202 ; Z_TAG_NUMBER : B50-MS1-XFR(T)-201 ;"


the string "Z_TAG_NUMBER" is repeating six times in the above cell contents. i want to extract out the z tag number to different cell. the output i want is "B50-MS1-XFR(T)-205 ; B50-MS1-XFR(T)-204 ; B50-MS1-XFR(T)-203 ; B50-MS1-XFR(T)-202 ; B50-MS1-XFR(T)-201 ;"

i have tried a for loop to attach a number to the "Z_TAG_NUMBER" so i could run a text to column, but couldnt.

Thanks,
Tharanipathy R

John Wilson
10-17-2016, 02:59 AM
I think you have posted in the wrong thread!