Class Phonetic (Excel VBA)

Contains information about a specific phonetic text string in a cell.

The main procedures of class Phonetic are Phonetics.Add and Phonetics.Delete

Set

To use a Phonetic class variable it first needs to be instantiated, for example

Dim lngIndex As Long: lngIndex = 
Dim rng As Range: Set rng = 
Dim phnPhonetic As Phonetic
Set phnPhonetic = rng.Phonetics(Index:=lngIndex)

The following procedures can be used to set variables of type Phonetic: Phonetics.Item, Range.Phonetic and Range.Phonetics

For Each

Here is an example of processing the Phonetic items in a collection.

Dim rng As Range: Set rng = 
Dim phnPhonetic As Phonetic
For Each phnPhonetic In rng.Phonetics
	
Next phnPhonetic

Methods

These are the main methods of the Phonetic class

Phonetics.Add - Adds phonetic text to the specified cell.

ActiveCell.FormulaR1C1 = "東京都渋谷区代々木" 
ActiveCell.Phonetics.Add Start:=1, Length:=3, Text:="トウキョウト" 
ActiveCell.Phonetics.Add Start:=4, Length:=3, Text:="シブヤク" 
ActiveCell.Phonetics.CharacterType = xlHiragana 
ActiveCell.Phonetics.Font.Color = vbBlue 
ActiveCell.Phonetics.Visible = True

Phonetics.Delete - Deletes the object.

Properties

Alignment returns or sets a Long value that represents the alignment for the specified phonetic text or tick label.

CharacterType returns or sets the type of phonetic text in the specified cell.

ActiveCell.Phonetics(1).CharacterType = xlHiragana

Font returns a Font object that represents the font of the specified object.

Parent returns the parent object for the specified object. Read-only.

Text returns or sets the text for the specified object.

Visible returns or sets a Boolean value that determines whether the object is visible.

Phonetics.Alignment returns or sets a Long value that represents the alignment for the specified phonetic text or tick label.

Phonetics.CharacterType returns or sets the type of phonetic text in the specified cell.

ActiveCell.Phonetics(1).CharacterType = xlHiragana

Phonetics.Count returns a Long value that represents the number of objects in the collection.

Phonetics.Font returns a Font object that represents the font of the specified object.

Phonetics.Item returns a single object from a collection.

ActiveCell.Phonetics.Item(1).Visible = True

Phonetics.Length returns a Long value that represents the number of characters of phonetic text from the position you've specified with the Start property.

ActiveCell.FormulaR1C1 = "東京都渋谷区代々木" 
ActiveCell.Phonetics.Add Start:=1, Length:=3, Text:="トウキョウト" 
ActiveCell.Phonetics.Add Start:=4, Length:=3, Text:="シブヤク" 
MsgBox ActiveCell.Phonetics(2).Length

Phonetics.Parent returns the parent object for the specified object. Read-only.

Phonetics.Start returns the position that represents the first character of a phonetic text string in the specified cell.

ActiveCell.FormulaR1C1 = "東京都渋谷区代々木" 
ActiveCell.Phonetics.Add Start:=1, Length:=3, Text:="トウキョウト" 
ActiveCell.Phonetics.Add Start:=4, Length:=3, Text:="シブヤク" 
MsgBox ActiveCell.Phonetics(2).Start

Phonetics.Text returns or sets the text for the specified object.

Phonetics.Visible returns or sets a Boolean value that determines whether the object is visible.