none
Change uppercase text to lowercase with Track Changes visible RRS feed

  • Question

  • Hi all,

    I am a beginner VBA user. I don’t have any formal training – what I know I’ve learned through trial and error and Googling, so please keep this in mind in your replies!

    I am working in an MS Word file that contains a lot of text written in title case (This is the Book Title, Each Word Capitalized) that needs to be changed to sentence case (This is the book title, only first word capitalized). All of the changes I make in the document should be tracked using the Track Changes function.

    I am looking for a way to automate this process such that the changes made are tracked. I know you can change selected text to lowercase by hitting Shift + F3 + F3. However, even if Track Changes are on, the change does not get tracked.

    So I wrote the following macro as a crude workaround. But when I run the code, it looks as if I deleted a lowercase letter and then added it back in, when in fact I deleted an uppercase letter, added it back in, and then changed the case. That is, the case change is applied invisibly and retroactively.

    Sub Lowercase4()

    Selection.Expand wdCharacter

    If Selection.Characters(1).Case = wdUpperCase Then

        Selection.Copy

        Selection.Delete

        Selection.Paste

        Selection.MoveLeft Unit:=wdCharacter, Count:=1

        Selection.Expand wdCharacter

        Selection.Range.Case = wdLowerCase

    Else

        Selection.MoveRight Unit:=wdCharacter, Count:=1

    End If

    End Sub

    Do you know of any other way to solve this problem? I don’t really care how the change is tracked (i.e., whether is it is recorded as, for example, “deleted: C” and “inserted: c” or “format: lowercase”), as long as it is tracked somehow.

    Thanks!

    Sunday, June 16, 2013 10:07 PM

Answers

  • How about

    Dim oRng As Range
    Dim strText As String
        Set oRng = Selection.Range
        If oRng.Characters.Last = Chr(13) Then
            oRng.End = oRng.End - 1
        End If
        strText = oRng.Text
        oRng.Text = strText
        oRng.Case = wdTitleWord


    Graham Mayor - Word MVP
    www.gmayor.com

    Monday, June 17, 2013 5:03 AM

All replies

  • How about

    Dim oRng As Range
    Dim strText As String
        Set oRng = Selection.Range
        If oRng.Characters.Last = Chr(13) Then
            oRng.End = oRng.End - 1
        End If
        strText = oRng.Text
        oRng.Text = strText
        oRng.Case = wdTitleWord


    Graham Mayor - Word MVP
    www.gmayor.com

    Monday, June 17, 2013 5:03 AM
  • That worked great, thanks! I modified it slightly so that only the first letter of each word is changed, and so that it skips to the next word if the first word it encounters is already lowercase:

    Sub Lowercase6()

    'If word begins with a capital, change to lowercase (Tracked)
    Selection.Expand wdCharacter
    If Selection.Characters(1).Case = wdUpperCase Then

    Dim oRng As Range
    Dim strText As String
        Set oRng = Selection.Range
         If oRng.Characters.Last = Chr(13) Then
         oRng.End = oRng.End - 1
         End If

    strText = oRng.Text
    oRng.Text = strText
    oRng.Case = wdLowerCase
    Selection.MoveRight Unit:=wdWord, Count:=1

    'If not, move to the beginning of the next word
    Else
    Selection.MoveRight Unit:=wdWord, Count:=1

    End If

    End Sub

    Thanks again!


    Monday, July 1, 2013 9:46 PM
  • You could simplify that further:

    Sub Lowercase6()
    Dim oRng As Range
    Dim strText As String
        Set oRng = Selection.Range
        oRng.Start = oRng.Words(1).Start
        oRng.End = oRng.Start + 1
        'If word begins with a capital, change to lowercase (Tracked)
        If oRng.Characters(1).Case = wdUpperCase Then
            strText = oRng.Text
            oRng.Text = strText
            oRng.Case = wdLowerCase
        End If
        'Move to the beginning of the next word
        Selection.MoveRight Unit:=wdWord, Count:=1
    End Sub


    Graham Mayor - Word MVP
    www.gmayor.com

    Tuesday, July 2, 2013 4:46 AM