2016-05-12 30 views
1

我的翻譯代碼不工作,因爲我想...它應該只在單元格的第一個單詞中執行Propercase,但它在單元格中的所有單詞中執行propercase 。VBA propercase在語言翻譯代碼修復

任何想法如何使它翻譯,並只使用activecase的第一個詞的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 
+1

您可以應用在字典中使用正確的外殼並使用StrComp()來測試不區分大小寫的對等關係 –

回答

2

就使第一個字母一個captial:

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 
+0

完美工作(:非常感謝 – ADrex