🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #17999

Re: Need a script for Change Case>Title Case

#17999
From: Stu Bloom
Date: Sun, 04 May 2003 17:11
45 lines
2182 bytes
Kelly,

You didn't specify AppleScript or VB. Here's a VB routine that will do a basic change-to-title-case. It assumes that the text to be shifted is the currently selected text.

If you wanted to get fancy, you could modify it to make articles and common prepositions all-lower-case (by providing an exception list).

Stu


Option Explicit

Sub Main()
    Dim objInDesign As InDesign.Application
    Dim objWord As InDesign.TextWord
    Dim sWord As String
    On Error GoTo CantChangeCase

Set objInDesign = CreateObject("InDesign.Application")
        If TypeName(objInDesign.Selection.Item(1)) = "Text" Then
            For Each objWord In objInDesign.Selection.Item(1).TextWords
                sWord = objWord.TextContents
                objWord.TextContents = TitleCase(sWord)
            Next
        Else
            MsgBox "You must have one or more characters of text selected to change case", vbExclamation, "InDesign Title Case Maker"
        End If
Exit Sub
CantChangeCase:
    MsgBox Err.Description, vbExclamation, "InDesign Title Case Maker"
Exit Sub
End Sub

Private Function TitleCase(ByRef sWord As String) As String
    Dim sFirst As String
    Dim sRest As String

sWord = Trim(sWord)
    If sWord <> vbNullString Then
        sFirst = UCase(Left(sWord, 1))
        If Len(sWord) > 1 Then
            sRest = LCase(Mid(sWord, 2))
        End If
    End If
    TitleCase = sFirst & sRest
End Function
Technical Details
Message-ID: <1de8f0bb.0@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebX
References: <1de8f0bb.-1@WebX.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,cb706e0ba6a97ab3
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-05-04 10:40:00 PST
From: "Stu Bloom" <stu@earlvillepost.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!nntp.infostrada.it!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: Re: Need a script for Change Case>Title Case
Message-ID: <1de8f0bb.0@WebX.la2eafNXanI>
Date: Sun, 4 May 2003 10:11:09 -0700
References: <1de8f0bb.-1@WebX.la2eafNXanI>
Lines: 50
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit