Excel VBA上正确的案例:如何添加一个规则并在整个工作表中应用该function

我正在使用下面的VBA代码将现有的工作表转换为正确的情况:

Sub Proper() Dim ws As Object Dim LCell As Range 'Move through each sheet in your spreadsheet For Each ws In ActiveWorkbook.Sheets 'Convert all constants and text values to proper case For Each LCell In Cells.SpecialCells(xlConstants, xlTextValues) LCell.Formula = StrConv(LCell.Formula, vbProperCase) Next Next ws End Sub 

这工作正常,除了我需要添加一个额外的规则的function。 在首字母后,第一个字母应该大写。

这里是一个例子: 谷歌(Android)应该成为谷歌(Android)

有没有办法编辑上面的代码来添加这个规则,或者我必须通过If条件循环每个字符?

您可以使用工作表函数:

 Sub Proper() Dim ws As Object Dim LCell As Range 'Move through each sheet in your spreadsheet For Each ws In ActiveWorkbook.Sheets ' Convert all constants and text values to proper case For Each LCell In Cells.SpecialCells(xlConstants, xlTextValues) LCell.Value = Application.WorksheetFunction.Proper(LCell) Next Next ws End Sub