I am very new to VBA coding but am realizing how powerful it is. To this point I have been using Autohotkey to automate Word, but it cannot handle one task I have in mind:
I want a macro that moves the insertion point to the beginning of the next sentence. Obviously the one built in to Word already is as follows:
Code:
Selection.MoveRight Unit:=wdSentence, Count:=1
But the thing I don’t like about this one is that it thinks a word like “Dr. ” or “Mr. ” or “Mrs. ” is the end of a sentence when in fact it is not. The spaces following the periods in my quotes are not an accident, because Word defines the end of a sentence as (1) a period plus a space or (2) simply a Paragraph sign (no period necessary for this second case). Thus, “A.a” would not be considered to be the end of a sentence because there is no space after the period.
So the only thing I want to change about Word’s definition of a sentence is to exclude certain words from its definition that I know are not the end of a sentence, like "Mr. " and the examples I give above. But writing this macro is proving elusive to me despite hours of trying to figure it out.
If any coding geniuses could whip up the perfect macro, that would be amazing. If not, could you help me with bits of it?
From my research, I am thinking I will have to define a Range that extends from the current insertion point position to the end of the next period plus space or the next new-paragraph sign, but not including instances such as “Dr. ” or “Mr. ” or “Mrs. ” Then I will move the insertion point from its current position to the end of that Range.
Also, from my understanding the only way to move the insertion point based on surrounding text is by using the "With Selection.Find" function, as described
here. Is that true?
This has a good example of how to exclude certain characters from a search using the Find function, but again, I am at a loss to write this complex code with my current knowledge.
Thank you so much to anyone willing to help!