I have the below code from an Excel macro that I would like to use in Word. Can someone help modify the code so that it will work?
Any help would be GREATLY appreciated!!Code:Sub ToggleTextCase()
'PURPOSE: Toggle selected cell text values between Upper, Lower, & Proper cases
'SOURCE: www.TheSpreadsheetGuru.com/the-code-vault
Dim FirstCellValue As String
Dim rng As Range
Dim cell As Range
'Optimize Code
Application.ScreenUpdating = False
'Was a Range Selected? (Error Handling)
If TypeName(Selection) <> "Range" Then
MsgBox "No cell range was selected!", vbCritical, "No Range Selected"
Exit Sub
End If
'Remove cells with formulas or cells that are hidden from selection
On Error Resume Next
If Selection.Cells.Count > 1 Then
Set rng = Selection.SpecialCells(xlCellTypeVisible)
Set rng = rng.SpecialCells(xlConstants)
Else
Set rng = ActiveCell
End If
'Store Current Case Structure of first cell in selection
FirstCellValue = rng.Cells(1, 1).Value
'Apply Case Change (based on first cell's current case structure)
If FirstCellValue = LCase(FirstCellValue) Then
'If Lowercased, make Propercased
For Each cell In rng.Cells
cell.Value = Application.WorksheetFunction.Proper(cell.Value)
Next cell
ElseIf FirstCellValue = UCase(FirstCellValue) Then
'If Uppercased, make Lowercased
For Each cell In rng.Cells
cell.Value = LCase(cell.Value)
Next cell
Else
'If Propercased, make Uppercased
For Each cell In rng.Cells
cell.Value = UCase(cell.Value)
Next cell
End If
End Sub