in Word VBA, What is a sentence?

J

John Wirt

I have what must be an easy general question.

What is included in the sentences collection of a range? Another way of
asking this is, how is a sentence defined in Word VBA?

Does a sentence consist of all the characters between two periods, less any
spaces at the beginning?

What about words at the end of a paragraph with no period. My experience is
that this would be included in the sentence collection, too.

Thanks.

John Wirt
 
J

Jean-Guy Marcil

Hi John,

Working with sentences can be tricky, especially if you have careless
users...

The content seems to change depending on which sentence you are talking
about.

First paragraph sentence:
From the first paragraph character (a space, a tab, a letter, etc.) to (an
including all spaces) the first character (but excluding that character)
after the first period in the paragraph. Here you might have a "sentence"
that starts with a bunch of spaces and finishes with a bunch of spaces.

Middle paragraph sentences:
From the first character following the end of the preceding sentence to (an
including all spaces) the first character (but excluding that character)
after the following period. So here, you do not normally get spaces at the
beginning of the sentence. There is an exception when using tabs. If two
sentences are separated by a bunch tabs, the first tab will be the end of
the first sentence, and all other tabs will be included with the beginning
of the next sentence. I guess they act as both a space and a character.

The last paragraph sentence:
The same as the middle sentences, with the important following exception: it
extends to (and excluding) the first character in a subsequent paragraph.
So, if a paragraph finishes with : "...tests. ¶" and is followed by two
¶'s ("¶¶"), then the last paragraph sentence will finish like this:
"...tests. ¶¶¶". But if, after the last "normal" sentence, you have this:
" ¶¶", then the end of the last sentence will be: "...tests. ¶"
Regardless, the last sentence always include the ¶ that signals the end of
the paragraph.

HTH
--
Cheers!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
J

John Wirt

Hmm...this is very interesting.
I have been having trouble with some code I'm trying to write (see these
newgroup apges) to extract revisions from a document by paragraph and
sentence number.

One big problem is that the documents I'm working with have paragraphs that
end in ¶ ¶ to ¶ ¶ ¶, etc., i.e., a paragraph with one or more "empty"
paragraphs following it.

The routine I've written (with assistance from subscribers here) prints out
the revisions one by one with their associated paragraph and sentence
numbers (see other articles under my name in this newsgroup). A problem is
that any revisions occurring in the pargraph ending in the first paragraph
mark above are repeated for every following "empty" paragraph until a
paragraph is reached. In fact, this printing of revisions is cummulative.
All revisions in successive non-empty paragraphs a printed out in total as
the document proceeds.

This pattern seems remarkably simliar to how you describe sentences are
treated in Word, with multiple paragraph marks associated with one
sentence..

John Wirt


The last paragraph sentence:
The same as the middle sentences, with the important following exception: it
extends to (and excluding) the first character in a subsequent paragraph.
So, if a paragraph finishes with : "...tests. ¶" and is followed by two
¶'s ("¶¶"), then the last paragraph sentence will finish like this:
"...tests. ¶¶¶". But if, after the last "normal" sentence, you have this:
" ¶¶", then the end of the last sentence will be: "...tests. ¶"
Regardless, the last sentence always include the ¶ that signals the end of>
 

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