Help with a Word macro that capitalizes the first letter of a word

I need a bit of code for a Word macro that will capitalize the first letter of a word if it's not already capitalized.  But if it is already capitalized, then I don't want it changed.

My current macro uses Shift-F3, which is Word's toggle between cap/not cap.  It works great when the target word is lower case, but if the word is already capped, it lower cases it, which is not what I want.

So, here's the situation in which I would use it.  Say there's a run-on sentence like this:

Mary likes apples Tom likes oranges.

I want to put my cursor after the s in apples and run the macro.  The macro should type a period, move over one space, add a second space, select the T in Tom, and capitalize it if it's not capitalized and leave it alone if it is capitalized.  Then I want the cursor to end up just to the left of the T in Tom.  

And here's my current code:

Sub insertaperiod()
' insertaperiod Macro
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.MoveRight Unit:=wdWord, Count:=1
    Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
    Selection.Range.Case = wdNextCase
    Selection.MoveLeft Unit:=wdCharacter, Count:=2
    Selection.TypeText Text:="."
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeText Text:=" "
End Sub

Thank you to this very helpful group!
Cindy GiovanettiTranscriptionAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe WinogradDeveloperCommented:
Hi Cindy,
We can leverage your new AutoHotkey Hyper (or Meh) solution again.

Make a new hotkey in your Hyper.ahk file with this in it:

ClipSave:=Clipboard ; save clipboard
Clipboard:="" ; clear clipboard
Send .{Right}{Space} ; send a period, right arrow, space
Send +{Right}^c ; copy the next character to the clipboard
ClipWait ; wait for char to appear on clipboard
If ClipChar is lower ; it is lower case
  StringUpper,ClipChar,ClipChar ; make it upper case
Send %ClipChar% ; paste over char
Clipboard:=ClipSave ; restore clipboard

Open in new window

I chose "k" this time for Kapitalize, since you're already using "c". As you know by now, Hyper+k will do it. Regards, Joe
Cindy GiovanettiTranscriptionAuthor Commented:
OK, I'm going to admit that I didn't use this method.  But your method inspired me to look for another method that was simpler.  Word has an all caps option under the Font menu, and I went with that.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Or you may simply replace the following line in your existing code...

Selection.Range.Case = wdNextCase

Open in new window


Selection.Text = StrConv(Selection.Text, vbUpperCase)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get Blueprints for Increased Customer Retention

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

Cindy GiovanettiTranscriptionAuthor Commented:
Oh my.  Thank you for that bit of code, Subodh!  That looks very helpful!
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You're welcome Cindy! Glad it worked as desired.
Cindy GiovanettiTranscriptionAuthor Commented:
I added that bit of code to many of my preexisting macros.  :)
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Great! Glad you found it useful. :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.