Skip to content

Instantly share code, notes, and snippets.

@ispedals
Created May 20, 2013 21:59
Show Gist options
  • Save ispedals/5615924 to your computer and use it in GitHub Desktop.
Save ispedals/5615924 to your computer and use it in GitHub Desktop.
Converts Aozora Bunko rubi format to Microsoft Word formatted phonetic guide
Sub rubier()
Dim pattern As String
Dim text As String
Dim parts() As String
Dim kana As String
Dim kanji As String
'pattern = [U+4E00-U+9FFF]{1,}U+12298?*U+12299
'pattern = \p{InCJK_Unified_Ideographs}{1,}\N{left double angle bracket}?*\N{right double angle bracket}
pattern = "[" & ChrW(19968) & "-" & ChrW(40959) & "]{1,}" & ChrW(12298) & "?*" & ChrW(12299)
Do While Selection.Find.Execute(FindText:=pattern, MatchWildcards:=True, Replace:=wdReplaceNone, Wrap:=wdFindContinue) = True
text = Selection.text
parts = Split(text, ChrW(12298))
kanji = parts(0)
kana = Replace(parts(1), ChrW(12299), "")
Selection.text = kanji
Selection.Range.PhoneticGuide text:=kana, Alignment:=wdPhoneticGuideAlignmentOneTwoOne
Loop
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment