Case switching

I have a bad habit of hitting the CapsLock key and when I type code, the shift key does the opposite,
so instead of typing m_bSomeVariable, I will look up and see that I have typed M_BsOMEvARIABLE.
DevStudio provides <Shift><U> and <Ctrl><Shift><U> to lower and upper case
a selection, but nothing provides a “SwapCase” function. The following macro will do the swap. I
assigned it to <Alt><U>, but that is entirely up to you ….

Sub SwapCase()
‘ DESCRIPTION: Macro to swap the case of selected words.

‘ David Little
‘ COADE, Inc.
‘ Houston, TX
[email protected]
‘ 5OCT98

str = ActiveDocument.Selection.Text
str1 = “”
i = 1
Do While (i < Len(str)+1) If (Mid(str, i, 1) = LCase(Mid(str, i, 1))) Then str1 = str1 + UCase(Mid(str, i, 1)) Else str1 = str1 + LCase(Mid(str, i, 1)) End If i = i + 1 Loop ActiveDocument.Selection.Text = str1 End Sub

More by Author

Must Read