I would like to point out, and only for the purpose of assisting knowledge, that...say you have the text:
THIS IS SOME TEXT.
Say it is the Style "Puzzle Text". Here is MakeItSo's core code snippet:
Code:
Do While Selection.Find.Found
For Each wd In Selection.Range.Words
wd.Case = wdLowerCase
wd.Characters(1).Case = wdUpperCase
Next wd
Selection.Collapse wdCollapseEnd
Selection.Find.Execute
Here is what it
actually does, the actual real instructions that are carried out, regarding the example "THIS IS SOME TEXT."
1. finds "THIS IS SOME TEXT."
2. sets the Variant wd as "THIS"
3. sets wd case attribute as LowerCase
4. sets wd 1st character attribute as UpperCase
5. sets the Variant wd as "IS"
6. sets wd case attribute as LowerCase
7. sets wd 1st character attribute as UpperCase
8. sets the Variant wd as "SOME"
9. sets wd case attribute as LowerCase
10. sets wd 1st character attribute as UpperCase
11. sets the Variant wd as "TEXT"
12. sets wd case attribute as LowerCase
13. sets wd 1st character attribute as UpperCase
14. sets the Variant wd as "."
15. sets wd case attribute as LowerCase
16. sets wd 1st character attribute as UpperCase
17. sets the Variant wd as vbCrLf (the paragraph mark)
18. sets wd case attribute as LowerCase
19. sets wd 1st character attribute as UpperCase
20. collapses the Selection
21. goes to the next .Execute of Selection.Find
Yes, the period (".") and the paragraph mark are considered separate and distinct "words", and since the code is:
Code:
[b][COLOR=red]For Each[/color red][/b] wd In Selection.Range.Words
they are indeed processed, each actioned with the instructions that every other "word" is actioned with.
Here is what using a Range
actually does, the actual real instructions that are carried out, regarding the example "THIS IS SOME TEXT."
1. finds "THIS IS SOME TEXT."
2. makes it TitleCase (either by word, or by sentence)
3. goes to the next .Execute of the range.Find
Look at the difference. Please, please, please, MakeItSo I am NOT, repeat not, being critical of your code. It works, and that, of course, is the main thing.
However, really understanding how Word "thinks" of things, the object model, makes a huge difference in:
1. writing cleaner, shorter, more efficient code
2. making it easier to debug your code, AND easier for
someone else to figure out what you are doing
3. getting working code up and running quicker, as you are
working
with how Word operates
4. understanding how documents are really structured, thus
designing/developing documents that take advantage of
that structure.
faq219-2884
Gerry
My paintings and sculpture