2016-05-12 5 views
1

私の翻訳コードは私が望むように機能しません...セルの最初の単語でのみPropercaseを実行する必要がありますが、セル内のすべての単語で適切なケースを実行しています。VBA propercase in language translation code fix

どのように翻訳を行い、activecellの最初の単語にのみ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

ただ、最初の文字キャピタル・します

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