|
koshimizu さん、お疲れ様でした。
でれすけさんもこられていたようですし、(ちょっと加工したものを)転載させていただきます。
引数 Flg(整数値) で戻ってくる文字列を分岐
-1以下 小文字のみ kana2roma("あいうえお",-1) → ”aiueo”
0 Proper kana2roma("あいうえお",0) → ”Aiueo”
1以上 大文字のみ kana2roma("あいうえお",1) → ”AIUEO”
Function kana2roma(ByVal kana As String, Flg As Integer) As String
Dim i As Integer, retStr As String
Dim ts As Boolean, tmp1 As String, tmp2 As String
Dim Cnv2(1 To 64, 1 To 2) As String, Cnv1(1 To 85, 1 To 2) As String
Cnv2(1, 1) = "きぃ": Cnv2(1, 2) = "kyi"
Cnv2(2, 1) = "きぇ": Cnv2(2, 2) = "kye"
Cnv2(3, 1) = "きゃ": Cnv2(3, 2) = "kya"
Cnv2(4, 1) = "きゅ": Cnv2(4, 2) = "kyu"
Cnv2(5, 1) = "きょ": Cnv2(5, 2) = "kyo"
Cnv2(6, 1) = "ぎぃ": Cnv2(6, 2) = "gyi"
Cnv2(7, 1) = "ぎぇ": Cnv2(7, 2) = "gye"
Cnv2(8, 1) = "ぎゃ": Cnv2(8, 2) = "gya"
Cnv2(9, 1) = "ぎゅ": Cnv2(9, 2) = "gyu"
Cnv2(10, 1) = "ぎょ": Cnv2(10, 2) = "gyo"
Cnv2(11, 1) = "しぃ": Cnv2(11, 2) = "syi"
Cnv2(12, 1) = "しぇ": Cnv2(12, 2) = "she"
Cnv2(13, 1) = "しゃ": Cnv2(13, 2) = "sha"
Cnv2(14, 1) = "しゅ": Cnv2(14, 2) = "shu"
Cnv2(15, 1) = "しょ": Cnv2(15, 2) = "sho"
Cnv2(16, 1) = "じぃ": Cnv2(16, 2) = "zyi"
Cnv2(17, 1) = "じぇ": Cnv2(17, 2) = "je"
Cnv2(18, 1) = "じゃ": Cnv2(18, 2) = "ja"
Cnv2(19, 1) = "じゅ": Cnv2(19, 2) = "ju"
Cnv2(20, 1) = "じょ": Cnv2(20, 2) = "jo"
Cnv2(21, 1) = "ちぃ": Cnv2(21, 2) = "tyi"
Cnv2(22, 1) = "ちぇ": Cnv2(22, 2) = "che"
Cnv2(23, 1) = "ちゃ": Cnv2(23, 2) = "cha"
Cnv2(24, 1) = "ちゅ": Cnv2(24, 2) = "chu"
Cnv2(25, 1) = "ちょ": Cnv2(25, 2) = "cho"
Cnv2(26, 1) = "ぢぃ": Cnv2(26, 2) = "dyi"
Cnv2(27, 1) = "ぢぇ": Cnv2(27, 2) = "dye"
Cnv2(28, 1) = "ぢゃ": Cnv2(28, 2) = "dya"
Cnv2(29, 1) = "ぢゅ": Cnv2(29, 2) = "dyu"
Cnv2(30, 1) = "ぢょ": Cnv2(30, 2) = "dyo"
Cnv2(31, 1) = "にぃ": Cnv2(31, 2) = "nyi"
Cnv2(32, 1) = "にぇ": Cnv2(32, 2) = "nye"
Cnv2(33, 1) = "にゃ": Cnv2(33, 2) = "nya"
Cnv2(34, 1) = "にゅ": Cnv2(34, 2) = "nyu"
Cnv2(35, 1) = "にょ": Cnv2(35, 2) = "nyo"
Cnv2(36, 1) = "ひぃ": Cnv2(36, 2) = "hyi"
Cnv2(37, 1) = "ひぇ": Cnv2(37, 2) = "hye"
Cnv2(38, 1) = "ひゃ": Cnv2(38, 2) = "hya"
Cnv2(39, 1) = "ひゅ": Cnv2(39, 2) = "hyu"
Cnv2(40, 1) = "ひょ": Cnv2(40, 2) = "hyo"
Cnv2(41, 1) = "びぃ": Cnv2(41, 2) = "byi"
Cnv2(42, 1) = "びぇ": Cnv2(42, 2) = "bye"
Cnv2(43, 1) = "びゃ": Cnv2(43, 2) = "bya"
Cnv2(44, 1) = "びゅ": Cnv2(44, 2) = "byu"
Cnv2(45, 1) = "びょ": Cnv2(45, 2) = "byo"
Cnv2(46, 1) = "ぴぃ": Cnv2(46, 2) = "pyi"
Cnv2(47, 1) = "ぴぇ": Cnv2(47, 2) = "pye"
Cnv2(48, 1) = "ぴゃ": Cnv2(48, 2) = "pya"
Cnv2(49, 1) = "ぴゅ": Cnv2(49, 2) = "pyu"
Cnv2(50, 1) = "ぴょ": Cnv2(50, 2) = "pyo"
Cnv2(51, 1) = "ふぁ": Cnv2(51, 2) = "fa"
Cnv2(52, 1) = "ふぃ": Cnv2(52, 2) = "fi"
Cnv2(53, 1) = "ふぇ": Cnv2(53, 2) = "fe"
Cnv2(54, 1) = "ふぉ": Cnv2(54, 2) = "fo"
Cnv2(55, 1) = "みぃ": Cnv2(55, 2) = "myi"
Cnv2(56, 1) = "みぇ": Cnv2(56, 2) = "mye"
Cnv2(57, 1) = "みゃ": Cnv2(57, 2) = "mya"
Cnv2(58, 1) = "みゅ": Cnv2(58, 2) = "myu"
Cnv2(59, 1) = "みょ": Cnv2(59, 2) = "myo"
Cnv2(60, 1) = "りぃ": Cnv2(60, 2) = "ryi"
Cnv2(61, 1) = "りぇ": Cnv2(61, 2) = "rye"
Cnv2(62, 1) = "りゃ": Cnv2(62, 2) = "rya"
Cnv2(63, 1) = "りゅ": Cnv2(63, 2) = "ryu"
Cnv2(64, 1) = "りょ": Cnv2(64, 2) = "ryo"
Cnv1(1, 1) = "ー": Cnv1(1, 2) = "-"
Cnv1(2, 1) = "ぁ": Cnv1(2, 2) = "xa"
Cnv1(3, 1) = "あ": Cnv1(3, 2) = "a"
Cnv1(4, 1) = "ぃ": Cnv1(4, 2) = "xi"
Cnv1(5, 1) = "い": Cnv1(5, 2) = "i"
Cnv1(6, 1) = "ぅ": Cnv1(6, 2) = "xu"
Cnv1(7, 1) = "う": Cnv1(7, 2) = "u"
Cnv1(8, 1) = "ぇ": Cnv1(8, 2) = "xe"
Cnv1(9, 1) = "え": Cnv1(9, 2) = "e"
Cnv1(10, 1) = "ぉ": Cnv1(10, 2) = "xo"
Cnv1(11, 1) = "お": Cnv1(11, 2) = "o"
Cnv1(12, 1) = "か": Cnv1(12, 2) = "ka"
Cnv1(13, 1) = "が": Cnv1(13, 2) = "ga"
Cnv1(14, 1) = "き": Cnv1(14, 2) = "ki"
Cnv1(15, 1) = "ぎ": Cnv1(15, 2) = "gi"
Cnv1(16, 1) = "く": Cnv1(16, 2) = "ku"
Cnv1(17, 1) = "ぐ": Cnv1(17, 2) = "gu"
Cnv1(18, 1) = "け": Cnv1(18, 2) = "ke"
Cnv1(19, 1) = "げ": Cnv1(19, 2) = "ge"
Cnv1(20, 1) = "こ": Cnv1(20, 2) = "ko"
Cnv1(21, 1) = "ご": Cnv1(21, 2) = "go"
Cnv1(22, 1) = "さ": Cnv1(22, 2) = "sa"
Cnv1(23, 1) = "ざ": Cnv1(23, 2) = "za"
Cnv1(24, 1) = "し": Cnv1(24, 2) = "shi"
Cnv1(25, 1) = "じ": Cnv1(25, 2) = "ji"
Cnv1(26, 1) = "す": Cnv1(26, 2) = "su"
Cnv1(27, 1) = "ず": Cnv1(27, 2) = "zu"
Cnv1(28, 1) = "せ": Cnv1(28, 2) = "se"
Cnv1(29, 1) = "ぜ": Cnv1(29, 2) = "ze"
Cnv1(30, 1) = "そ": Cnv1(30, 2) = "so"
Cnv1(31, 1) = "ぞ": Cnv1(31, 2) = "zo"
Cnv1(32, 1) = "た": Cnv1(32, 2) = "ta"
Cnv1(33, 1) = "だ": Cnv1(33, 2) = "da"
Cnv1(34, 1) = "ち": Cnv1(34, 2) = "chi"
Cnv1(35, 1) = "ぢ": Cnv1(35, 2) = "di"
Cnv1(36, 1) = "つ": Cnv1(36, 2) = "tsu"
Cnv1(37, 1) = "づ": Cnv1(37, 2) = "du"
Cnv1(38, 1) = "て": Cnv1(38, 2) = "te"
Cnv1(39, 1) = "で": Cnv1(39, 2) = "de"
Cnv1(40, 1) = "と": Cnv1(40, 2) = "to"
Cnv1(41, 1) = "ど": Cnv1(41, 2) = "do"
Cnv1(42, 1) = "な": Cnv1(42, 2) = "na"
Cnv1(43, 1) = "に": Cnv1(43, 2) = "ni"
Cnv1(44, 1) = "ぬ": Cnv1(44, 2) = "nu"
Cnv1(45, 1) = "ね": Cnv1(45, 2) = "ne"
Cnv1(46, 1) = "の": Cnv1(46, 2) = "no"
Cnv1(47, 1) = "は": Cnv1(47, 2) = "ha"
Cnv1(48, 1) = "ば": Cnv1(48, 2) = "ba"
Cnv1(49, 1) = "ぱ": Cnv1(49, 2) = "pa"
Cnv1(50, 1) = "ひ": Cnv1(50, 2) = "hi"
Cnv1(51, 1) = "び": Cnv1(51, 2) = "bi"
Cnv1(52, 1) = "ぴ": Cnv1(52, 2) = "pi"
Cnv1(53, 1) = "ふ": Cnv1(53, 2) = "fu"
Cnv1(54, 1) = "ぶ": Cnv1(54, 2) = "bu"
Cnv1(55, 1) = "ぷ": Cnv1(55, 2) = "pu"
Cnv1(56, 1) = "へ": Cnv1(56, 2) = "he"
Cnv1(57, 1) = "べ": Cnv1(57, 2) = "be"
Cnv1(58, 1) = "ぺ": Cnv1(58, 2) = "pe"
Cnv1(59, 1) = "ほ": Cnv1(59, 2) = "ho"
Cnv1(60, 1) = "ぼ": Cnv1(60, 2) = "bo"
Cnv1(61, 1) = "ぽ": Cnv1(61, 2) = "po"
Cnv1(62, 1) = "ま": Cnv1(62, 2) = "ma"
Cnv1(63, 1) = "み": Cnv1(63, 2) = "mi"
Cnv1(64, 1) = "む": Cnv1(64, 2) = "mu"
Cnv1(65, 1) = "め": Cnv1(65, 2) = "me"
Cnv1(66, 1) = "も": Cnv1(66, 2) = "mo"
Cnv1(67, 1) = "ゃ": Cnv1(67, 2) = "xya"
Cnv1(68, 1) = "や": Cnv1(68, 2) = "ya"
Cnv1(69, 1) = "ゅ": Cnv1(69, 2) = "xyu"
Cnv1(70, 1) = "ゆ": Cnv1(70, 2) = "yu"
Cnv1(71, 1) = "ょ": Cnv1(71, 2) = "xyo"
Cnv1(72, 1) = "よ": Cnv1(72, 2) = "yo"
Cnv1(73, 1) = "ら": Cnv1(73, 2) = "ra"
Cnv1(74, 1) = "り": Cnv1(74, 2) = "ri"
Cnv1(75, 1) = "る": Cnv1(75, 2) = "ru"
Cnv1(76, 1) = "れ": Cnv1(76, 2) = "re"
Cnv1(77, 1) = "ろ": Cnv1(77, 2) = "ro"
Cnv1(78, 1) = "わ": Cnv1(78, 2) = "wa"
Cnv1(79, 1) = "ゐ": Cnv1(79, 2) = "wi"
Cnv1(80, 1) = "ゑ": Cnv1(80, 2) = "we"
Cnv1(81, 1) = "を": Cnv1(81, 2) = "wo"
Cnv1(82, 1) = "ん": Cnv1(82, 2) = "nn"
Cnv1(83, 1) = "ゑ": Cnv1(83, 2) = "we"
Cnv1(84, 1) = "を": Cnv1(84, 2) = "wo"
Cnv1(85, 1) = "ん": Cnv1(85, 2) = "nn"
kana = StrConv(kana, vbHiragana Or vbWide)
retStr = "": i = 1: ts = False
Do While i <= Len(kana)
tmp2 = "": tmp1 = ""
On Error Resume Next
tmp2 = Application.WorksheetFunction.VLookup(Mid(kana, i, 2), Cnv2(), 2, False)
tmp1 = Application.WorksheetFunction.VLookup(Mid(kana, i, 1), Cnv1(), 2, False)
On Error GoTo 0
If tmp2 <> "" Then
If ts Then
retStr = retStr & Left(tmp2, 1)
End If
retStr = retStr & tmp2
i = i + 2
ts = False
ElseIf tmp1 <> "" Then
If ts Then
retStr = retStr & Left(tmp1, 1)
End If
retStr = retStr & tmp1
i = i + 1
ts = False
ElseIf Mid(kana, i, 1) = "っ" Then
ts = True
i = i + 1
Else
retStr = retStr & Mid(kana, i, 1)
i = i + 1
End If
Loop
'
Select Case Sgn(Flg)
Case 0: retStr = StrConv(retStr, vbProperCase) '0の時はProper
Case 1: retStr = StrConv(retStr, vbUpperCase)
End Select
'
kana2roma = retStr
End Function
こんな感じです。
|
|