コーディング規約でヘボン式を使用するならこの関数

コーディング規約などで、日本語からアルファベットへの変換は「ヘボン式」を使うことと規定されていることがある。

そんなときは、Excelマクロで一気に変換すると楽だ。使い方はこんな感じ。

=hebooon(PHONETIC(A1))

 

Function hebooon(str As String) As String

    Dim spr As Variant
    Dim rtn As String
   

    A(0) = "ッ,"
    A(1) = "っ,"
    A(2) = "きゅう,KYU"
    A(3) = "しゅう,SHU"
    A(4) = "ちゅう,CHU"
    A(5) = "にゅう,NYU"
    A(6) = "ひゅう,HYU"
    A(7) = "みゅう,MYU"
    A(8) = "りゅう,RYU"
    A(9) = "きゅう,GYU"
    A(10) = "じゅう,JU"
    A(11) = "びゅう,BYU"
    A(12) = "ぴゅう,PYU"
    A(13) = "きょう,KYO"
    A(14) = "しょう,SHO"
    A(15) = "ちょう,CHO"
    A(16) = "にょう,NYO"
    A(17) = "ひょう,HYO"
    A(18) = "みょう,MYO"
    A(19) = "りょう,RYO"
    A(20) = "ぎょう,GYO"
    A(21) = "じょう,JO"
    A(22) = "びょう,BYO"
    A(23) = "ぴょう,PYO"
    A(24) = "きゃ,KYA"
    A(25) = "きゅ,KYU"
    A(26) = "きょ,KYO"
    A(27) = "しゃ,SHA"
    A(28) = "しゅ,SHU"
    A(29) = "しょ,SHO"
    A(30) = "ちゃ,CHA"
    A(31) = "ちゅ,CHU"
    A(32) = "ちょ,CHO"
    A(33) = "にゃ,NYA"
    A(34) = "にゅ,NYU"
    A(35) = "にょ,NYO"
    A(36) = "ひゃ,HYA"
    A(37) = "ひゅ,HYU"
    A(38) = "ひょ,HYO"
    A(39) = "みゃ,MYA"
    A(40) = "みゅ,MYU"
    A(41) = "みょ,MYO"
    A(42) = "りゃ,RYA"
    A(43) = "りゅ,RYU"
    A(44) = "りょ,RYO"
    A(45) = "ぎゃ,GYA"
    A(46) = "ぎゅ,GYU"
    A(47) = "ぎょ,GYO"
    A(48) = "じゃ,JA"
    A(49) = "じゅ,JU"
    A(50) = "じょ,JO"
    A(51) = "びゃ,BYA"
    A(52) = "びゅ,BYU"
    A(53) = "びょ,BYO"
    A(54) = "ぴゃ,PYA"
    A(55) = "ぴゅ,PYU"
    A(56) = "ぴょ,PYO"
    A(57) = "おう,O"
    A(58) = "おお,O"
    A(59) = "こう,KO"
    A(60) = "そう,SO"
    A(61) = "とう,TO"
    A(62) = "のう,NO"
    A(63) = "ほう,HO"
    A(64) = "もう,MO"
    A(65) = "よう,YO"
    A(66) = "ろう,RO"
    A(67) = "ごう,GO"
    A(68) = "ぞう,ZO"
    A(69) = "どう,DO"
    A(70) = "ぼう,BO"
    A(71) = "ぽう,PO"
    A(72) = "あ,A"
    A(73) = "か,KA"
    A(74) = "さ,SA"
    A(75) = "た,TA"
    A(76) = "な,NA"
    A(77) = "は,HA"
    A(78) = "ま,MA"
    A(79) = "や,YA"
    A(80) = "ら,RA"
    A(81) = "わ,WA"
    A(82) = "が,GA"
    A(83) = "ざ,ZA"
    A(84) = "だ,DA"
    A(85) = "ば,BA"
    A(86) = "ぱ,PA"
    A(87) = "い,I"
    A(88) = "き,KI"
    A(89) = "し,SHI"
    A(90) = "ち,CHI"
    A(91) = "に,NI"
    A(92) = "ひ,HI"
    A(93) = "み,MI"
    A(94) = "り,RI"
    A(95) = "ぎ,GI"
    A(96) = "じ,JI"
    A(97) = "ぢ,JI"
    A(98) = "び,BI"
    A(99) = "ぴ,PI"
    A(100) = "う,U"
    A(101) = "く,KU"
    A(102) = "す,SU"
    A(103) = "つ,TSU"
    A(104) = "ぬ,NU"
    A(105) = "ふ,FU"
    A(106) = "む,MU"
    A(107) = "ゆ,YU"
    A(108) = "る,RU"
    A(109) = "を,O"
    A(110) = "ぐ,GU"
    A(111) = "ず,ZU"
    A(112) = "づ,ZU"
    A(113) = "ぶ,BU"
    A(114) = "ぷ,PU"
    A(115) = "え,E"
    A(116) = "け,KE"
    A(117) = "せ,SE"
    A(118) = "て,TE"
    A(119) = "ね,NE"
    A(120) = "へ,HE"
    A(121) = "め,ME"
    A(122) = "れ,RE"
    A(123) = "げ,GE"
    A(124) = "ぜ,ZE"
    A(125) = "で,DE"
    A(126) = "べ,BE"
    A(127) = "ぺ,PE"
    A(128) = "お,O"
    A(129) = "こ,KO"
    A(130) = "そ,SO"
    A(131) = "と,TO"
    A(132) = "の,NO"
    A(133) = "ほ,HO"
    A(134) = "も,MO"
    A(135) = "よ,YO"
    A(136) = "ろ,RO"
    A(137) = "ん,N"
    A(138) = "ご,GO"
    A(139) = "ぞ,ZO"
    A(140) = "ど,DO"
    A(141) = "ぼ,BO"
    A(142) = "ぽ,PO"
    A(143) = "キュウ,KYU"
    A(144) = "シュウ,SHU"
    A(145) = "チュウ,CHU"
    A(146) = "ニュウ,NYU"
    A(147) = "ヒュウ,HYU"
    A(148) = "ミュウ,MYU"
    A(149) = &quot
;リュウ,RYU"
    A(150) = "キュウ,GYU"
    A(151) = "ジュウ,JU"
    A(152) = "ビュウ,BYU"
    A(153) = "ピュウ,PYU"
    A(154) = "キョウ,KYO"
    A(155) = "ショウ,SHO"
    A(156) = "チョウ,CHO"
    A(157) = "ニョウ,NYO"
    A(158) = "ヒョウ,HYO"
    A(159) = "ミョウ,MYO"
    A(160) = "リョウ,RYO"
    A(161) = "ギョウ,GYO"
    A(162) = "ジョウ,JO"
    A(163) = "ビョウ,BYO"
    A(164) = "ピョウ,PYO"
    A(165) = "キャ,KYA"
    A(166) = "キュ,KYU"
    A(167) = "キョ,KYO"
    A(168) = "シャ,SHA"
    A(169) = "シュ,SHU"
    A(170) = "ショ,SHO"
    A(171) = "チャ,CHA"
    A(172) = "チュ,CHU"
    A(173) = "チョ,CHO"
    A(174) = "ニャ,NYA"
    A(175) = "ニュ,NYU"
    A(176) = "ニョ,NYO"
    A(177) = "ヒャ,HYA"
    A(178) = "ヒュ,HYU"
    A(179) = "ヒョ,HYO"
    A(180) = "ミャ,MYA"
    A(181) = "ミュ,MYU"
    A(182) = "ミョ,MYO"
    A(183) = "リャ,RYA"
    A(184) = "リュ,RYU"
    A(185) = "リョ,RYO"
    A(186) = "ギャ,GYA"
    A(187) = "ギュ,GYU"
    A(188) = "ギョ,GYO"
    A(189) = "ジャ,JA"
    A(190) = "ジュ,JU"
    A(191) = "ジョ,JO"
    A(192) = "ビャ,BYA"
    A(193) = "ビュ,BYU"
    A(194) = "ビョ,BYO"
    A(195) = "ピャ,PYA"
    A(196) = "ピュ,PYU"
    A(197) = "ピョ,PYO"
    A(198) = "オウ,O"
    A(199) = "オオ,O"
    A(200) = "コウ,KO"
    A(201) = "ソウ,SO"
    A(202) = "トウ,TO"
    A(203) = "ノウ,NO"
    A(204) = "ホウ,HO"
    A(205) = "モウ,MO"
    A(206) = "ヨウ,YO"
    A(207) = "ロウ,RO"
    A(208) = "ゴウ,GO"
    A(209) = "ゾウ,ZO"
    A(210) = "ドウ,DO"
    A(211) = "ボウ,BO"
    A(212) = "ポウ,PO"
    A(213) = "ア,A"
    A(214) = "カ,KA"
    A(215) = "サ,SA"
    A(216) = "タ,TA"
    A(217) = "ナ,NA"
    A(218) = "ハ,HA"
    A(219) = "マ,MA"
    A(220) = "ヤ,YA"
    A(221) = "ラ,RA"
    A(222) = "ワ,WA"
    A(223) = "ガ,GA"
    A(224) = "ザ,ZA"
    A(225) = "ダ,DA"
    A(226) = "バ,BA"
    A(227) = "パ,PA"
    A(228) = "イ,I"
    A(229) = "キ,KI"
    A(230) = "シ,SHI"
    A(231) = "チ,CHI"
    A(232) = "ニ,NI"
    A(233) = "ヒ,HI"
    A(234) = "ミ,MI"
    A(235) = "リ,RI"
    A(236) = "ギ,GI"
    A(237) = "ジ,JI"
    A(238) = "ヂ,JI"
    A(239) = "ビ,BI"
    A(240) = "ピ,PI"
    A(241) = "ウ,U"
    A(242) = "ク,KU"
    A(243) = "ス,SU"
    A(244) = "ツ,TSU"
    A(245) = "ヌ,NU"
    A(246) = "フ,FU"
    A(247) = "ム,MU"
    A(248) = "ユ,YU"
    A(249) = "ル,RU"
    A(250) = "ヲ,O"
    A(251) = "グ,GU"
    A(252) = "ズ,ZU"
    A(253) = "ヅ,ZU"
    A(254) = "ブ,BU"
    A(255) = "プ,PU"
    A(256) = "エ,E"
    A(257) = "ケ,KE"
    A(258) = "セ,SE"
    A(259) = "テ,TE"
    A(260) = "ネ,NE"
    A(261) = "ヘ,HE"
    A(262) = "メ,ME"
    A(263) = "レ,RE"
    A(264) = "ゲ,GE"
    A(265) = "ゼ,ZE"
    A(266) = "デ,DE"
    A(267) = "ベ,BE"
    A(268) = "ペ,PE"
    A(269) = "オ,O"
    A(270) = "コ,KO"
    A(271) = "ソ,SO"
    A(272) = "ト,TO"
    A(273) = "ノ,NO"
    A(274) = "ホ,HO"
    A(275) = "モ,MO"
    A(276) = "ヨ,YO"
    A(277) = "ロ,RO"
    A(278) = "ン,N"
    A(279) = "ゴ,GO"
    A(280) = "ゾ,ZO"
    A(281) = "ド,DO"
    A(282) = "ボ,BO"
    A(283) = "ポ,PO"
    A(284) = "ー,"
    A(285) = "OO,O" ‘前の母音で代用
    A(286) = "UU,U" ‘「ウウ」の発音になる文字は「u」一文字で表す。

   
    rtn = str
   
    Dim s As Variant
    ‘変換表に基づく変換。
    For Each s In A
        spr = Split(s, ",")
        rtn = Replace(rtn, spr(0), spr(1))
    Next
   
    hebooon = rtn
End Function

上部へスクロール