MS Word macro/shortcut for changing selection to sentence case
Thread poster: Samuel Murray

Samuel Murray  Identity Verified
Netherlands
Local time: 09:05
Member (2006)
English to Afrikaans
+ ...
May 17, 2015

Hello everyone

I have a document in which I have to change several lines to sentence case. These lines typically use a combination of sentence case and title case, but I need them changed to sentence case. What I mean by "sentence case" is that the first letter in my selection is capitalised and the rest of the letters are turned into lowercase (or alternatively, the first letter in a sentence or paragraph is capitalised, and all other letters are turned to lowercase -- both definitions would suit me). Does anyone know of a macro that does that?

The built-in function of MS Word to change text to "sentence case" only changes the first character in the selection to a capital letter if it is lowercase, and only if the selection includes the entire first word of the sentence or paragraph, and does not affect the rest of the sentence, so... it's a fairly useless feature.

I mean, if I have "the Quick Brown FOX jumps over the Lazy Dog", then I want it changed to "The quick brown fox jumps over the lazy dog". MS Word's built-in function only changes the first "the" to "The" but leaves the rest of the text untouched.

My current solution is to select all text except the first letter, and then toggle the "lowercase" case in MS Word, but that requires two shortcut presses and it requires me to perform this action every time for each line (I may have a dozen consecutive lines that all need that action applied to them).

Got any ideas?

Thanks
Samuel


Direct link Reply with quote
 

Michael Joseph Wdowiak Beijer  Identity Verified
United Kingdom
Local time: 08:05
Member (2009)
Dutch to English
+ ...
CafeTran shortcut "Change case" May 17, 2015

Hi Samuel,

Probably not much use to you, but I just checked in CafeTran and I can do what you're trying to achieve using the CafeTran shortcut "Change case". Please note that I do need to press it four times to produce the desired output.

The first press converts

the Quick Brown FOX jumps over the Lazy Dog

into:

The Quick Brown FOX jumps over the Lazy Dog

the second press converts the above into:

THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG

the third press converts the above into:

the quick brown fox jumps over the lazy dog

and the fourth press turns the above into:

The quick brown fox jumps over the lazy dog

Michael

PS: you said you had "a document", but not what format it is in, and whether you are working in a CAT tool, etc.


Direct link Reply with quote
 

Rossana Triaca  Identity Verified
Uruguay
Local time: 04:05
Member (2002)
English to Spanish
AutoHotKey May 18, 2015

I had a macro for this lying around in AHK (it's not unicode though so watch out for special characters, I think Afrikaans uses a couple of those).

It's really easy to tweak too... this is set to use windows key + caps lock, but you can use whatever hotkey you like.

-------------
#CAPSLOCK::

Clip_Save:= ClipboardAll
Clipboard:= ""
Send ^c{delete}
StringLower, Clipboard, Clipboard
Clipboard := RegExReplace(Clipboard, "(((^|([.!?]+\s+))[a-z])| i | i')", "$u1")
Send %Clipboard%
Len:= Strlen(Clipboard)
Send +{left %Len%}
Clipboard:= Clip_Save
--------------

Hope it helps!

[Edited at 2015-05-18 04:15 GMT]


Direct link Reply with quote
 
xxx2nl  Identity Verified
Netherlands
Local time: 09:05
You can use this macro May 18, 2015

You can use this macro:



Direct link Reply with quote
 
Terry Richards
France
Local time: 09:05
French to English
+ ...
What's wrong with... May 18, 2015

...this:

Selection.Range.Case = wdLowerCase
Selection.Range.Case = wdTitleSentence

The first line sets the current selection to all lower case and the second sets it to sentence case. I tested it and it works fine for multiple sentences in the selection.


Direct link Reply with quote
 
wotswot  Identity Verified
France
Local time: 09:05
Member (2011)
French to English
Changing Word's Shift-F3 (change case) May 18, 2015

Samuel,

If you're comfortable with VBA, here's how to do it in Word.

In a start-up macro-enabled template (in Normal.dotm, but I recommend writing another one for your own customizations), create a module then paste the following code:

Option Explicit

Public Sub AutoExec()
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'NB This only fires if this file is a global template, i.e. in Word's Startup folder: in Win7:
'C:\Users\\AppData\Roaming\Microsoft\Word\STARTUP
' THIS Autoexec fires AFTER the one in Normal.dot
'and BEFORE the routines in the 'ThisDocument class module
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
AssignKeyBordShortcut ' Moved to separate Public Sub below
'(to call from Outlook for instance, if Word is set as default editor)
End Sub

Public Sub AssignKeyBordShortcut
'You can use this logic to create/modify any keyboard shortcut
Dim MyKeyCode As Long
Dim MyCommand As String
Application.CustomizationContext = NormalTemplate
MyKeyCode = BuildKeyCode(Arg1:=wdKeyShift, Arg2:=wdKeyF3)
MyCommand = "Check_ShiftF3"
KeyBindings.Add KeyCode:=MyKeyCode, KeyCategory:=wdKeyCategoryMacro, Command:=MyCommand
End Sub

Public Sub Check_ShiftF3()
ConvertCaseWordSel
End Sub

Public Sub ConvertCaseWordSel()
'Press Shift-F3 1, 2, 3 or 4 times
If Selection.Range.Case = 0 Then ' lowercase
Selection.Range.Case = 1 'uppercase
ElseIf Selection.Range.Case = 1 Then 'UPPERCASE
Selection.Range.Case = 2 'Proper Case
ElseIf Selection.Range.Case = 2 Then 'Proper Case
Selection.Range.Case = 4 'Sentence case
Else
Selection.Range.Case = 0 'lowercase
End If
End Sub


Direct link Reply with quote
 

Tina Vonhof  Identity Verified
Canada
Local time: 01:05
Member (2006)
Dutch to English
+ ...
Two clicks May 18, 2015

Use the Change Case feature in Word. First change the entire selection to lower case and then choose sentence case.

I see that Terry has already suggested this, it seems the simplest way of doing it.




[Edited at 2015-05-18 15:07 GMT]


Direct link Reply with quote
 

Michael Grant
Japan
Local time: 16:05
Japanese to English
Try the built-in shortcut: Shift+F3 to change case. May 19, 2015

[NOTE] 1) The Shift+F3 combination works for me, unlike the OP described, so there may be version/settings differences that explain why it doesn't work for him. 2) In further testing, I found that this method does not recognize proper nouns (i.e. company/product names, etc.) so its use cases are limited, to say the least. [/NOTE]

Word (at least Word 2007) has a default keyboard shortcut to change the case of selected text:

Shift+F3

Pressing that key combination will change the case of the text you select text from "ALL CAPS" to "all lowercase" to "Sentence case."

So, if the text you select is originally in all UPPERCASE letters, pressing Shift+F3 once will change it to all lowercase letters, and then pressing Shift+F3 again will change it to sentence case. Pressing it yet again will change it back to all UPPERCASE (i.e. it cycles the text between the three cases).

The cool thing about this is that it is smart enough to respect individual sentences, so if you select an entire paragraph, or indeed, the entire document, this keyboard shortcut will change the individual sentences into sentence case!

What's more, it is even smart enough to treat decimals as decimals, and periods as periods!

Be sure to try it on a copy just in case the results aren't what you expect.

Michael

[Edited at 2015-05-19 00:51 GMT]

[Edited at 2015-05-19 00:55 GMT]

[Edited at 2015-05-19 01:08 GMT]


Direct link Reply with quote
 

Rolf Keller
Germany
Local time: 09:05
English to German
Making macros more readable & reliable May 19, 2015

wotswot wrote:

Public Sub ConvertCaseWordSel()
'Press Shift-F3 1, 2, 3 or 4 times


You may use wdLowerCase, wdUpperCase & wdTitleWord instead of the numeric constants.


Direct link Reply with quote
 

Samuel Murray  Identity Verified
Netherlands
Local time: 09:05
Member (2006)
English to Afrikaans
+ ...
TOPIC STARTER
Thanks, everyone May 19, 2015

Michael Beijer wrote:
...and the fourth press turns the above into:
The quick brown fox jumps over the lazy dog


Thanks, but I would rather avoid a solution that requires me to press a shortcut four times for every line of text.

PS: you said you had "a document", but not what format it is in, and whether you are working in a CAT tool, etc.


The title of the post says "MS Word".

Rossana Triaca wrote:
I had a macro for this lying around in AHK (it's not unicode though so watch out for special characters, I think Afrikaans uses a couple of those).


Thanks, that appears like a simple solution.

I haven't tried it, but something tells me that whether it would work would depend on whether one has the "smart paste" feature disabled in MS Word or not. You know, the "feature" (I call it a bug) that inserts a space if you select text from the middle of a word and then cut it.

Terry Richards wrote:
Selection.Range.Case = wdLowerCase
Selection.Range.Case = wdTitleSentence


Aah, thanks for that last line -- I could not figure out what is the VB function for activating what MS Word calls "sentence case".

Tina Vonhof wrote:
Two clicks


Thanks, but I'd rather avoid anything that requires "clicks", because it means I have to move my mouse very carefully to click in the right place, which leads to a condition known as mouse elbow.

Michael Grant wrote:
1) The Shift+F3 combination works for me, unlike the OP described, so there may be version/settings differences that explain why it doesn't work for him.


For this file, I'm using Word 2003, but I expected the shortcut to function similarly in subsequent versions.

Pressing that key combination will change the case of the text you select text from "ALL CAPS" to "all lowercase" to "Sentence case."


In my case, it toggles not between all caps, all lowercase and sentence case, but between all caps, all lowercase and title case. The title case option is sometimes not available with Shift+F3, depending on how MS Word interprets the case of the original text. Either way, my version of MS Word's definition of "sentence case" seems to be "first letter of the first word of a sentence in selected text changed to uppercase" and not "first letter of the first word of a sentence in selected text changed to uppercase and all other letters changed to lowercase".


Direct link Reply with quote
 

Michael Joseph Wdowiak Beijer  Identity Verified
United Kingdom
Local time: 08:05
Member (2009)
Dutch to English
+ ...
extra shortcut (four in one) May 19, 2015

Samuel Murray wrote:

Michael Beijer wrote:
...and the fourth press turns the above into:
The quick brown fox jumps over the lazy dog


Thanks, but I would rather avoid a solution that requires me to press a shortcut four times for every line of text.



Yeah, if I had to actually use this myself tons of times in a long document or on a regular basis I'd probably make a quick AutoHotkey (or KnowBrainer 2015 voice command!) shortcut that pressed the shortcut four times in one go.

The cool thing about this CafeTran shortcut is that it cycles through the various case types that you might need, thus combining multiple cases into a single shortcut.

Michael


Direct link Reply with quote
 


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

MS Word macro/shortcut for changing selection to sentence case

Advanced search






SDL Trados Studio 2017 Freelance
The leading translation software used by over 250,000 translators.

SDL Trados Studio 2017 helps translators increase translation productivity whilst ensuring quality. Combining translation memory, terminology management and machine translation in one simple and easy-to-use environment.

More info »
SDL MultiTerm 2017
Guarantee a unified, consistent and high-quality translation with terminology software by the industry leaders.

SDL MultiTerm 2017 allows translators to create one central location to store and manage multilingual terminology, and with SDL MultiTerm Extract 2017 you can automatically create term lists from your existing documentation to save time.

More info »



Forums
  • All of ProZ.com
  • Term search
  • Jobs
  • Forums
  • Multiple search