'MacroName:ChangeCase 'MacroDescription:Changes the case of selected text. ' ' This macro was written by Walter F. Nickeson, ' University of Rochester, Rochester, NY ' wnickeson@library.rochester.edu ' ' Last updated: 5 September 2007. ' Check for the latest versions of this and my other macros at ' http://docushare.lib.rochester.edu/docushare/dsweb/View/Collection-2556 ' Please e-mail me with bug reports or to suggest improvements. ' ' Works in Connexion client 2.10. ' '*************************************************************** ' How it works. Select some text in a record and run the macro. ' It will give you the option to change the selected text to ' Sentence case, Initial Capitals Case, lowercase, UPPERCASE, or ' Title Case. After you choose which modification to run, the ' modified text is put back in the record, replacing the ' selected text. ' ' Changing the selection to Sentence case means that the first ' letter of the selection, and any letter that follows a period ' (full stop) and a space, is capitalized. Changing the ' selection to Initial Capitals Case means that every letter ' that follows a space is capitalized. Changing the selection to ' Title Case means that after first modifying it to Initial ' Capitals Case, the macro (following the Chicago Manual of ' Style) lowercases articles, coordinate conjunctions, and ' prepositions, by comparing each "word" (a string bounded by ' spaces) in the selection to a list of such words. ' ' These simple rules may produce, in some circumstances, results ' that seem odd. '*************************************************************** Option Explicit Sub Main Dim CS As Object Set CS = CreateObject("Connex.Client") Dim CaseInitials$ Dim CaseLower$ Dim CaseSentence$ Dim CaseTitle$ Dim CaseUpper$ Dim SelectedText$ Dim Word$ Dim Start% Dim p, q ' First, begin by verifying that text has been selected If CS.GetSelectedText( SelectedText$ ) = FALSE Then MsgBox "Please select some text to change its case!", 64, "No text selected" GoTo Done: End If ' For mass changing of text to all upper and lower case, use the ' simple BASIC commands CaseUpper$ = UCase$( SelectedText$ ) CaseLower$ = LCase$( SelectedText$ ) ' For Sentence case, take the string just made completely ' lowercase, and capitalize the first letter and any subsequent ' letter following a period and a space, assuming such a letter ' begins a new sentence CaseSentence$ = CaseLower$ If Asc( Mid$( CaseSentence$, 1, 1 ) ) > 96 and Asc( Mid$( CaseSentence$, 1, 1 ) ) < 123 Then Mid$( CaseSentence$, 1, 1 ) = Chr$( Asc( Left$( CaseSentence$, 1 ) ) - 32 ) End If Start% = 1 Do p = InStr( Start%, CaseSentence$, ". " ) If p > 0 And p < Len( CaseSentence$ ) Then Mid$( CaseSentence$, p + 2, 1 ) = Chr$( Asc( Mid$( CaseSentence$, p + 2, 1 ) ) - 32 ) End If Start% = p + 1 Loop Until p = 0 ' For Initial Case, take the string just transformed for ' Sentence case, and make every character following a space ' uppercase CaseInitials$ = CaseSentence$ Start% = 1 Do q = InStr( Start%, CaseInitials$, " " ) If q > 0 And q < Len( CaseInitials$) Then If Asc( Mid$( CaseInitials$, q + 1, 1 ) ) > 96 And Asc( Mid$( CaseInitials$, q + 1, 1 ) ) < 123 Then Mid$( CaseInitials$, q + 1, 1 ) = Chr$( Asc( Mid$( CaseInitials$, q + 1, 1 ) ) - 32 ) End If End If Start% = q + 1 Loop Until q = 0 ' For Title case, take the string just transformed for Initial ' Case, and lowercase articles, coordinate conjunctions, and ' prepositions (following Chicago Manual of Style rules). ' Examine each word (a string bounded by spaces), compare it to ' the list of words to not capitalize, and lowercase as ' necessary CaseTitle$ = CaseInitials$ Start% = 1 Do q = InStr( Start%, CaseTitle$, " " ) If q > 0 And q < Len( CaseTitle$) Then Word$ = Mid$( CaseTitle$, Start%, q - Start% ) Select Case Word$ Case "A", "Aboard", "About", "Above", "Absent", "Across", "After", "Against", _ "Along", "Alongside", "Amid", "Amidst", "Among", "Amongst", "An", "And", _ "Around", "As", "Aslant", "Astride", "At", "Atop", "Barring", "Before", _ "Behind", "Below", "Beneath", "Beside", "Besides", "Between", "Beyond", "But", _ "By", "Concerning", "Considering", "Despite", "Down", "During", "Except", _ "Excepting", "Excluding", "Failing", "Following", "For", "From", "In", _ "Inside", "Into", "Like", "Mid", "Minus", "Near", "Next", "Nor", _ "Notwithstanding", "Of", "Off", "On", "Onto", "Opposite", "Or", "Outside", _ "Over", "Past", "Per", "Plus", "Regarding", "Round", "Save", "Since", "Than", _ "The", "Through", "Throughout", "Till", "Times", "To", "Toward", "Towards", _ "Under", "Underneath", "Unlike", "Until", "Up", "Upon", "Versus", "Via", _ "With", "Within", "Without" If Start% <> 1 Then Mid$( Word$, 1, 1 ) = Chr$( Asc( Left$( Word$, 1 ) ) + 32 ) Mid$( CaseTitle$, Start%, Len( Word$ ) ) = Word$ End If End Select End If Start% = q + 1 Loop Until q = 0 Begin Dialog PresentChoices 178, 168, "Change case of selected text" Text 44, 10, 90, 10, "Change case of selection to ..." OptionGroup .OptionGroup1 OptionButton 28, 26, 122, 14, "&Sentence case.", .OptionButton1 OptionButton 28, 44, 122, 14, "Initial &Capital Letters", .OptionButton2 OptionButton 28, 62, 122, 14, "&lowercase", .OptionButton3 OptionButton 28, 80, 122, 14, "&UPPERCASE", .OptionButton4 OptionButton 28, 98, 122, 14, "&Title Case (Chicago Manual of Style)", .OptionButton5 Text 38, 110, 112, 24, "(articles, conjunctions, and prepositions not capitalized)" OkButton 24, 138, 54, 16 CancelButton 100, 138, 54, 16 End Dialog Dim CaseOptions as PresentChoices On Error Resume Next Dialog CaseOptions If Err = 102 Then GoTo Done: Select Case CaseOptions.OptionGroup1 Case 0 If CS.SetSelectedText (CaseSentence$) = FALSE Then GoTo Failure: Case 1 If CS.SetSelectedText (CaseInitials$) = FALSE Then GoTo Failure: Case 2 If CS.SetSelectedText (CaseLower$) = FALSE Then GoTo Failure: Case 3 If CS.SetSelectedText (CaseUpper$) = FALSE Then GoTo Failure: Case 4 If CS.SetSelectedText (CaseTitle$) = FALSE Then GoTo Failure: End Select GoTo Done: Failure: MsgBox "Sorry, could not change case of the selection.", 48, "Macro failure" Done: End Sub