Repeatedly Change First Letter After [period][blank] to Uppercase

  • Thread starter Don Macnaughton
  • Start date
D

Don Macnaughton

I'm developing a macro in Word 2003 to convert text from point form to
finished test. One step is supposed to find the string [period][blank] i.e.,
the end of each sentence. Then it's supposed to convert the character
immediately following this string to uppercase because this character will be
the first letter in the next sentence, which therefore should be in
uppercase. Here's what I've been trying to use, which converts a large
number of consecutive characters to uppercase:

With ActiveDocument.Content.Find
.Text = ". "
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False

Do While .Execute = True
With .Parent
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Range.Case = wdUpperCase
.Move Unit:=wdSentence, Count:=1
End With
Loop
End With

Thanks for your help.
 
L

Lene Fredborg

The problem is that you use the range object to find the text (which is
fine), but you apply the changes to the selection and not the range you
found. Therefore, what your macro does is that it changes the characters
found after the selection you had when starting the macro - the number of
characters changed equals the number of ". " found. If you use F8 to step
through the macro, you can see what happens.

You could change the Do-Loop in you macro to the following (note that the
code below also applies uppercase to ". " - but since uppercase and
lowercase of ". " are identical, this is OK).

Do While .Execute = True
With .Parent
Include the next character
.End = .End + 1
'Change to uppercase
.Case = wdUpperCase
'Make sure to move on to next ". "
.Start = .End
End With
Loop

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
 

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