Trouble with sentences.count returning a misleading value

D

david.f.jenkins

In PowerPoint, I have inserted and selected a text box containing a
blank line followed by two bullets. Here is the code that I am using
to examine that text:

Sub test()

Dim t As TextRange
Dim i As Integer
Dim str As String

Set t = ActiveWindow.Selection.TextRange

For i = 1 To t.Sentences.Count
str = t.Sentences(i).text
Next i

End Sub


When I run the code, t.sentences.count shows as 2. However, the loop
returns the following values:

t.Sentences(1).text = ""
t.Sentences(2).text = "Bullet 1"

if I change the max loop index to t.sentences.count + 1, then

t.Sentences(3).text = "Bullet 2"

It appears to me that the Count method is returning a spurious value,
but there may be some subtleties in its use that I'm missing. Can
someone shed some light on what's going on here? And how I might
program around this? BTW, when the blank line in the text box is
between Bullet 1 and Bullet 2, I don't see this behavior.

Thanks!
 
S

Steve Rindsberg

..Sentences does seem to work oddly, but then perhaps it's not the best method
to use in this case anyhow. Note that if you have a period instead of a blank
line, it works as you'd expect.

There seems to be an inconsistency between what considers a sentence when it
returns .Count and when it returns .Sentence(x)

Bullets = Paragraphs though, and not sentences.

You can only have a bullet at the beginning of a paragraph, but there might be
more than one sentence in each paragraph.

If you substitute .Paragraphs for .Sentences, your code should work as
expected.
 
D

david.f.jenkins

Steve: your suggestion has made life immeasurably easier - thanks!

Ummm...don't you think that the Sentences() method is exhibiting buggy
behavior, rather than simply inconsistent? Don't you think someone
should get that fixed?
 
S

Steve Rindsberg

Steve: your suggestion has made life immeasurably easier - thanks!

Ummm...don't you think that the Sentences() method is exhibiting buggy
behavior, rather than simply inconsistent? Don't you think someone
should get that fixed?

I'd consider the inconsistency a bug, yep.
And I'll at least try to get it kicked along upstairs in the hopes that it gets
fixed in a later SP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top