Results 1 to 2 of 2

Thread: Detecting & Modifying Phonetic Text in a Selection

  1. #1

    Detecting & Modifying Phonetic Text in a Selection


    I am working on a Word VBA sub to automate tasks that I can readily do in the UI or by working with Open XML directly, but finding it unexpectedly difficult in VBA. For text that has phonetic guide text applied (aka Ruby Annotation, Furigana), I would like to access just the phonetic text. My goal is to then check spelling, and change its font color to red.

    How can you get to just this phonetic text from a Selection, by drilling through properties and functions? The Open XML equivalent that I'm after would be the w:rt node under the selection.

    Searching the document for a keyword in the phonetic guide text, Word will find it, then its color can be changed separate from the base text. It seems that there should be a way to do the same with VBA.



  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Jul 2008
    If you know what the pnetic works are, you could use code like:
    Sub CheckWords()
    Application.ScreenUpdating = False
    Dim strWords As String, i As Long
    strWords = strWords & "a,am,an,are,been,began,brought,can,check,come,"
    strWords = strWords & "do,find,found,get,give,go,have,hear,let,lot,"
    strWords = strWords & "make,may,me,might,number,numeral,oh,plain,plane,"
    strWords = strWords & "pose,pound,query,quiet,quite,ran,run,say,see,"
    strWords = strWords & "should,song,spell,state,stood,those,take,would"
    With ActiveDocumentRange.Find
      .Forward = True
      .Format = True
      .MatchCase = False
      .MatchWholeWord = False
      .MatchWildcards = False
      .MatchSoundsLike = False
      .MatchAllWordForms = False
      .Wrap = wdFindContinue
      With .Replacement
        .Text = "^&"
        .Font.Color = wdColorRed
      End With
      For i = 0 To UBound(Split(strWords, ","))
        .Text = Split(strWords, ",")(i)
        .Execute Replace:=wdReplaceAll
      Next i
    End With
    Application.ScreenUpdating = True
    End Sub
    and replace the various words in the strWords variable with the phonetic words you're concerned with. You can add/delete
    strWords definition lines as desired - just ensure all except the last terminate with a comma followed by a double quote; the final line should have
    double quote but not the preceding comma.
    Paul Edstein
    [MS MVP - Word]

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts