下面的VBA代碼可以將活動工作表中的所有文本字符串的首字母改為大寫,對包含公式單元格則不作更改。
Sub CapitalizeFirstLetter()
Dim Rng As Range
ActiveSheet.UsedRange.Select
For Each Rng In Selection.Cells
If Rng.HasFormula = False Then
Rng.Value = Application.WorksheetFunction.Proper(Rng.Value)
End If
Next Rng
End Sub