Capitalise Each Word

FrecklePaw
2StarLounger
Posts: 130
Joined: 12 Aug 2020, 08:40

Capitalise Each Word

Post by FrecklePaw »

Is there any way in the Font > Capitalise Each Word option to change it so that the likes of and, for, of, etc. are not capitalised along with the rest?

e.g.
International Fund for Agricultural Development
Department of Health and Social Care

Perhaps not and it's just a set thing, but thought I would ask just in case!

TIA,
FP

User avatar
SpeakEasy
4StarLounger
Posts: 563
Joined: 27 Jun 2021, 10:46

Re: Capitalise Each Word

Post by SpeakEasy »

No - but a macro such as the following could work:

Code: Select all

Sub myCapitalise()

    Dim mysel As Range
    Selection.Range.Case = wdTitleWord
    For Each mysel In Selection.Words
        If InStr("the in one on at of a for and", LCase(Trim(mysel))) > 0 Then
            mysel.Case = wdLowerCase
        End If
    Next

End Sub

User avatar
HansV
Administrator
Posts: 78549
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Capitalise Each Word

Post by HansV »

Word has no built-in way to do this, but see True title case for a macro that you can use.
If you save the code in a module in your default template Normal.dotm, it will always be available. You can assign it to a keyboard shortcut and/or Quick Access Toolbar button for ease of use.

I have attached a demo document with the code - all credit goes to Graham Mayor.

TrueTitleCase.docm
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

FrecklePaw
2StarLounger
Posts: 130
Joined: 12 Aug 2020, 08:40

Re: Capitalise Each Word

Post by FrecklePaw »

I didn't think this was going to be possible! That's really helpful, thank you :)

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Capitalise Each Word

Post by ChrisGreaves »

FrecklePaw wrote:
25 Sep 2023, 10:28
I didn't think this was going to be possible! That's really helpful, thank you :)
I have a more complicated version which uses a stored (on disk) reference string:-

Code: Select all

ProperTitleReference=,a,all,an,and,are,as,can,do,for,from,in,is,it,of,on,or,so,that,the,this,to,up,was,we,with,has,gone,vs,
I use my macro for titling text in a document, and as well, for saving files with a proper name.
Cheers, Chris
You do not have the required permissions to view the files attached to this post.
He who plants a seed, plants life.

snb
4StarLounger
Posts: 586
Joined: 14 Nov 2012, 16:06

Re: Capitalise Each Word

Post by snb »

Code: Select all

Sub M_snb()
  Selection.Range.Case = 0

  For Each it In Selection.Words
    If Len(Trim(it)) > 3 Then it.Case = 2
  Next
End Sub

User avatar
ChrisGreaves
PlutoniumLounger
Posts: 15641
Joined: 24 Jan 2010, 23:23
Location: brings.slot.perky

Re: Capitalise Each Word

Post by ChrisGreaves »

snb wrote:
25 Sep 2023, 12:41
If Len(Trim(it)) > 3 Then it.Case = 2
Hi snb. This is a beautifully concise method. I found that it was a bit too simple for my needs. I needed to fine-tune with a small dictionary.
Of course, a great deal depends on the object. I was in the business of cleaning up documents from a variety of sources. Had I developed that further I would probably have implemented a reference string for each client.

In my example of saving as filenames, I now think that using MSWord's blanket capitalization makes more sense for file names as we tend to want to read file names as a series of distinct strings/words rather than a grammatically correct sentence.

Cheers, Chris
He who plants a seed, plants life.

User avatar
SpeakEasy
4StarLounger
Posts: 563
Joined: 27 Jun 2021, 10:46

Re: Capitalise Each Word

Post by SpeakEasy »

Here's my version tweaked to deal with initial capital and colons as per TrueTitleCase (and using the same word list, which can of course be modified)

Code: Select all

Sub myCapitalise()
    Dim skipnext As Boolean
    Dim mysel As Range
    
    Selection.Range.Case = wdTitleWord
    skipnext = True
    For Each mysel In Selection.Words
        If skipnext Then
            skipnext = False
        ElseIf InStr("a an and as at but by for if in of on or the to with", LCase(Trim(mysel))) > 0 Then
            mysel.Case = wdLowerCase
        ElseIf Right(Trim(mysel), 1) = ":" Then
            skipnext = True
        End If
    Next
End Sub

snb
4StarLounger
Posts: 586
Joined: 14 Nov 2012, 16:06

Re: Capitalise Each Word

Post by snb »

then I'd prefer:

Code: Select all

Sub M_snb()
  For Each it In Selection.Words
    it.Case = 2 * (Abs(InStr(" a an and as at but by for if in of on or the to with ", " " & it) = 0))
  Next
End Sub