塵芥回顧録

掃き溜めのようなブログ(?)

ひらがなをヘボン式ローマ字に変換する関数

ひらがなをヘボン式ローマ字に変換するマクロを作ってみた。
ヘボン式の仕組みが複雑でミスもあるかもしれないので注意してください。

Function HEBON(word As String) As String
 
  Dim SEARCH As String
  Dim SEARCH2 As String
  Dim BSEARCH As String
  Dim RESULT As String
  
  For i = 1 To LEN(word)
  
	SEARCH = MID(word,i,1)
    
	Select Case SEARCH
	Case "あ" 
	RESULT = RESULT & "A"
	Case "い","ゐ"
	RESULT = RESULT & "I"
	Case "う" 
	If BSEARCH = "" Or BSEARCH = " " Or BSEARCH = " " Then RESULT = RESULT & "U"
	Case "え","ゑ"
	RESULT = RESULT & "E"
	Case "お","を"
	SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case ""," "," "
		RESULT = RESULT & "O"
		Case Else
		If BSEARCH = "" Or BSEARCH = " " Or BSEARCH = " " Then RESULT = RESULT & "O"
		End Select
	Case "か"
	RESULT = RESULT & "KA"
	Case "き"
	SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "KY"
		Case Else
		RESULT = RESULT & "KI"
		End Select
	Case "く"
	RESULT = RESULT & "KU"
	Case "け"
	RESULT = RESULT & "KE"
	Case "こ"
	RESULT = RESULT & "KO"
	Case "さ"
	RESULT = RESULT & "SA"
	Case "し"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "SH"
		Case Else
		RESULT = RESULT & "SHI"
		End Select
	Case "す"
	RESULT = RESULT & "SU"
	Case "せ"
	RESULT = RESULT & "SE"
	Case "そ"
	RESULT = RESULT & "SO"
	Case "た"
	RESULT = RESULT & "TA"
	Case "ち"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "CH"
		Case Else
		RESULT = RESULT & "CHI"
		End Select
	Case "つ"
	RESULT = RESULT & "TSU"
	Case "て"
	RESULT = RESULT & "TE"
	Case "と"
	RESULT = RESULT & "TO"
	Case "な"
	RESULT = RESULT & "NA"
	Case "に"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "NY"
		Case Else
		RESULT = RESULT & "NI"
		End Select
	Case "ぬ"
	RESULT = RESULT & "NU"
	Case "ね"
	RESULT = RESULT & "NE"
	Case "の"
	RESULT = RESULT & "NO"
	Case "は"
	RESULT = RESULT & "HA"
	Case "ひ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "HY"
		Case Else
		RESULT = RESULT & "HI"
		End Select
	Case "ふ"
	RESULT = RESULT & "FU"
	Case "へ"
	RESULT = RESULT & "HE"
	Case "ほ"
	RESULT = RESULT & "HO"
	Case "ま"
	RESULT = RESULT & "MA"
	Case "み"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "MY"
		Case Else
		RESULT = RESULT & "MI"
		End Select
	Case "む"
	RESULT = RESULT & "MU"
	Case "め"
	RESULT = RESULT & "ME"
	Case "も"
	RESULT = RESULT & "MO"
	Case "や"
	RESULT = RESULT & "YA"
	Case "ゆ"
	RESULT = RESULT & "YU"
	Case "よ"
	RESULT = RESULT & "YO"
	Case "ら"
	RESULT = RESULT & "RA"
	Case "り"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "RY"
		Case Else
		RESULT = RESULT & "RI"
		End Select
	Case "る"
	RESULT = RESULT & "RU"
	Case "れ"
	RESULT = RESULT & "RE"
	Case "ろ"
	RESULT = RESULT & "RO"
	Case "わ"
	RESULT = RESULT & "WA"
	Case "ん"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ば","び","ぶ","べ","ぼ","ヴ","ま","み","む","め","も","ぱ","ぴ","ぷ","ぺ","ぽ"
		RESULT = RESULT & "M"
		Case Else
		RESULT = RESULT & "N"
		End Select
	
	Case "が"
	RESULT = RESULT & "GA"
	Case "ぎ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "GY"
		Case Else
		RESULT = RESULT & "GI"
		End Select
	Case "ぐ"
	RESULT = RESULT & "GU"
	Case "げ"
	RESULT = RESULT & "GE"
	Case "ご"
	RESULT = RESULT & "GO"
	Case "ざ"
	RESULT = RESULT & "ZA"
	Case "じ","ぢ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "J"
		Case Else
		RESULT = RESULT & "JI"
		End Select
	Case "ず","づ"
	RESULT = RESULT & "ZU"
	Case "ぜ"
	RESULT = RESULT & "ZE"
	Case "ぞ"
	RESULT = RESULT & "ZO"
	Case "だ"
	RESULT = RESULT & "DA"
	Case "で"
	RESULT = RESULT & "DE"
	Case "ど"
	RESULT = RESULT & "DO"
	Case "ば"
	RESULT = RESULT & "BA"
	Case "び"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "BY"
		Case Else
		RESULT = RESULT & "BI"
		End Select
	Case "ぶ"
	RESULT = RESULT & "BU"
	
	Case "べ"
	RESULT = RESULT & "BE"
	Case "ぼ"
	RESULT = RESULT & "BO"
	Case "ぱ"
	RESULT = RESULT & "PA"
	Case "ぴ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "ゃ","ゅ","ょ"
		RESULT = RESULT & "PY"
		Case Else
		RESULT = RESULT & "PI"
		End Select
	Case "ぷ"
	RESULT = RESULT & "PU"
	Case "ぺ"
	RESULT = RESULT & "PE"
	Case "ぽ"
	RESULT = RESULT & "PO"
	
	Case "っ"
		SEARCH2 = MID(word,i+1,1)
		Select Case SEARCH2
		Case "か","き","く","け","こ"
		RESULT = RESULT & "K"
		Case "さ","し","す","せ","そ"
		RESULT = RESULT & "S"
		Case "た","ち","つ","て","と"
		RESULT = RESULT & "T"
		Case "な","に","ぬ","ね","の"
		RESULT = RESULT & "N"
		Case "は","ひ","へ","ほ"
		RESULT = RESULT & "H"
		Case "ふ"
		RESULT = RESULT & "F"		
		Case "ま","み","む","め","も"
		RESULT = RESULT & "M"
		Case "や","ゆ","よ"
		RESULT = RESULT & "Y"
		Case "ら","り","る","れ","ろ"
		RESULT = RESULT & "R"
		Case "わ"
		RESULT = RESULT & "W"
		
		Case "が","ぎ","ぐ","げ","ご"
		RESULT = RESULT & "G"
		Case "ざ","ず","ぜ","ぞ","づ"
		RESULT = RESULT & "Z"
		Case "じ"
		RESULT = RESULT & "J"
		Case "だ","づ","で","ど"
		RESULT = RESULT & "D"
		Case "ば","び","ぶ","べ","ぼ","ヴ","ゔ"
		RESULT = RESULT & "B"
		Case "ぱ","ぴ","ぷ","ぺ","ぽ"
		RESULT = RESULT & "P"
		End select
	
	Case "ヴ","ゔ"
	RESULT = RESULT & "BU"
	
	Case "ぁ","ゃ"
	RESULT = RESULT & "A"
	Case "ぃ"
	RESULT = RESULT & "I"
	Case "ぅ","ゅ"
	RESULT = RESULT & "U"
	Case "ぇ"
	RESULT = RESULT & "E"
	Case "ぉ","ょ"
	RESULT = RESULT & "O"
	
	Case Else
	RESULT = RESULT & SEARCH
	End select
	
	BSEARCH = SEARCH
  
  Next i
	
  HEBON = RESULT
 
End Function