我的翻译代码没有按照我想要的方式工作......它应该仅在单元格的第一个单词中执行Propercase,但它在单元格中的所有单词中都是正确的。
关于如何翻译并且仅在activecell中的第一个单词上使用大写字母的任何想法?
以下是代码:
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
答案 0 :(得分:2)
将第一个字母设为首字母:
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