事前設定:Microsoft Scripting Runtimeへの参照設定
Function ConvertAlphabetToKatakana(str As String) As String
Dim alphaToKana As Dictionary
Set alphaToKana = New Dictionary
' アルファベットとカタカナの対応表
alphaToKana.CompareMode = vbTextCompare ' 大文字小文字を区別しない
alphaToKana.Add "A", "エー"
alphaToKana.Add "B", "ビー"
alphaToKana.Add "C", "シー"
alphaToKana.Add "D", "ディー"
alphaToKana.Add "E", "イー"
alphaToKana.Add "F", "エフ"
alphaToKana.Add "G", "ジー"
alphaToKana.Add "H", "エイチ"
alphaToKana.Add "I", "アイ"
alphaToKana.Add "J", "ジェー"
alphaToKana.Add "K", "ケー"
alphaToKana.Add "L", "エル"
alphaToKana.Add "M", "エム"
alphaToKana.Add "N", "エヌ"
alphaToKana.Add "O", "オー"
alphaToKana.Add "P", "ピー"
alphaToKana.Add "Q", "キュー"
alphaToKana.Add "R", "アール"
alphaToKana.Add "S", "エス"
alphaToKana.Add "T", "ティー"
alphaToKana.Add "U", "ユー"
alphaToKana.Add "V", "ブイ"
alphaToKana.Add "W", "ダブリュー"
alphaToKana.Add "X", "エックス"
alphaToKana.Add "Y", "ワイ"
alphaToKana.Add "Z", "ゼット"
Dim result As String
Dim i As Integer
For i = 1 To Len(str)
Dim ch As String
ch = Mid(str, i, 1)
If alphaToKana.Exists(UCase(ch)) Then
result = result & alphaToKana(UCase(ch))
Else
result = result & ch ' 対応するカタカナがない場合はそのまま追加
End If
Next i
ConvertAlphabetToKatakana = result
End Function
コメント