-
"The code that I provided works well for periods, but how do I incorporate other delimiters like ; or :
Further, I also want to be able to distinguish certain keywords like Ph.D. or U.S. "
The only way would be to write logic that will determine those strings.
"For the research that I am doing, I need to look at sentences and not at paragraphs.
So basically I want Excel to recognize a sentence"
The problem is that there is no Sentence object. Sentences are ranges. A period (".") is a period...ummm, period. Word does not know what it means, except within certain context. If that context is not the context YOU want (e.g. Ph.D, or U.S.) then...yes, it can be done, but YOU have to tell Word what the logic criteria is.
This is, perhaps unfortunately, the way things work in Word. macropod's suggestion is - as you acknowledge - the most efficient starting point. If it does not work for you, then you will have to work with the code you have, and expand it to logically determine if the "." is applicable....or not.
I have to point out that your code:[vba]
With aRange.Find
Do
.Text = ". " ' the word I am looking for
[/vba]is not technically correct in the comment "the word I am looking for". It is a string...not a "word".
Now for the example Ph.D, that "." will NOT be found, as the .Text string given is ". " Period followed by a space.
In the example U.S., the first "." will not be found - ever -, and the second would be found IF it is followed by a space. However, as you undoubtedly realize, "U.S." will have a space if the string "U.S." is in a sentence, rather than at the end of a sentence. Still, with the code you have, what is actually found is ". "
Not "U.S. "
Bottom line? If YOU have determined that:
This is some text; followed by some more text.
is actually TWO sentences - because of the semi-colon - then you have to make it two sentences. Word will consider it one sentence.
How?
By testing to see if the sentence you now have as the range:[vba]
aRange.Expand Unit:=wdSentence
[/vba]has one of your required delimiters. If it does, then you will have to write, and action, the logic to make that string into two sentences. Or three, or whatever.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules