VBA 语言翻译代码中的适当大小写修复
VBA propercase in language translation code fix
我的翻译代码没有按我想要的那样工作...它应该只在单元格的第一个单词中使用 Propercase,但它在单元格中的所有单词中都使用了 Propercase。
关于如何使其翻译并仅在活动单元格中的第一个单词上使用适当大小写的任何想法?
代码如下:
Sub traducaobeta2()
Dim translate As Object 'scritping.Dictionary
Set translate = CreateObject("Scripting.Dictionary")
translate("cadeira") = "chair"
translate("cadeira,") = "chair"
translate("cadeiras") = "chairs"
translate("criado mudo") = "night stand"
translate("criado-mudo") = "night stand"
translate("mesa") = "table"
translate("mesas") = "tables"
translate("e") = "and"
' the list goes on...
Dim Words As Variant
Dim I As Integer
Words = Split(LCase(activecell.Value))
For I = LBound(Words) To UBound(Words)
If translate(Words(I)) <> "" Then Words(I) = translate(Words(I))
Next
activecell.Value = Join(Words)
For Each x In activecell
x.Value = Application.Proper(x.Value)
Next
activecell.Offset(0, 1).Select
End Sub
只需将首字母大写:
ActiveCell.value = UCase$(Left$(ActiveCell.value, 1)) & Right$(ActiveCell.value, Len(ActiveCell.value) - 1)
也可以使用 With
块来节省输入:
With ActiveCell
.value = UCase$(Left$(.value, 1)) & Right$(.value, Len(.value) - 1)
End With
我的翻译代码没有按我想要的那样工作...它应该只在单元格的第一个单词中使用 Propercase,但它在单元格中的所有单词中都使用了 Propercase。
关于如何使其翻译并仅在活动单元格中的第一个单词上使用适当大小写的任何想法?
代码如下:
Sub traducaobeta2()
Dim translate As Object 'scritping.Dictionary
Set translate = CreateObject("Scripting.Dictionary")
translate("cadeira") = "chair"
translate("cadeira,") = "chair"
translate("cadeiras") = "chairs"
translate("criado mudo") = "night stand"
translate("criado-mudo") = "night stand"
translate("mesa") = "table"
translate("mesas") = "tables"
translate("e") = "and"
' the list goes on...
Dim Words As Variant
Dim I As Integer
Words = Split(LCase(activecell.Value))
For I = LBound(Words) To UBound(Words)
If translate(Words(I)) <> "" Then Words(I) = translate(Words(I))
Next
activecell.Value = Join(Words)
For Each x In activecell
x.Value = Application.Proper(x.Value)
Next
activecell.Offset(0, 1).Select
End Sub
只需将首字母大写:
ActiveCell.value = UCase$(Left$(ActiveCell.value, 1)) & Right$(ActiveCell.value, Len(ActiveCell.value) - 1)
也可以使用 With
块来节省输入:
With ActiveCell
.value = UCase$(Left$(.value, 1)) & Right$(.value, Len(.value) - 1)
End With