用Strconv("this is a test",vbProperCase)可以把每个单词的第一个字母变为大写

解决方案 »

  1.   

    那要让它变成 "This is a test.",也就是只把每句话的首字母改变该怎么办?
      

  2.   

    Private Sub Command1_Click()
    MsgBox UCaseFirstChar("qTTThis is a test")
    End Sub
    Public Function UCaseFirstChar(StringX As String) As String
    If VBA.Asc(VBA.Left(StringX, 1)) >= VBA.Asc("a") And VBA.Asc(VBA.Left(StringX, 1)) <= VBA.Asc("z") Then
       UCaseFirstChar = VBA.Replace(StringX, VBA.Left(StringX, 1), VBA.UCase(VBA.Left(StringX, 1)), , 1)
    Else
       UCaseFirstChar = StringX
    End If
    End Function