- 1 year ago
PowerPoint VBA: Identify/replace Lao text in DokChampa font
To identify and replace Lao text in the DokChampa font in PowerPoint VBA, you can use the following code:
vbaSub ReplaceLaoTextWithFont()
Dim slide As Slide
Dim shape As Shape
Dim textRange As TextRange
' Loop through all slides in the active presentation
For Each slide In ActivePresentation.Slides
' Loop through all shapes in the slide
For Each shape In slide.Shapes
' Check if the shape has text
If shape.HasTextFrame Then
Set textRange = shape.TextFrame.TextRange
' Check if the text range contains Lao characters in the DokChampa font
If ContainsLaoDokChampaFont(textRange) Then
' Replace the Lao text with the desired replacement
ReplaceLaoTextWithReplacement(textRange)
End If
End If
Next shape
Next slide
End Sub
Function ContainsLaoDokChampaFont(textRange As TextRange) As Boolean
' Loop through each character in the text range
For i = 1 To textRange.Length
' Check if the character is in the Lao Unicode range
If IsLaoCharacter(textRange.Characters(i).Unicode) Then
' Check if the character has the DokChampa font
If textRange.Characters(i).Font.Name = "DokChampa" Then
' Found Lao text in DokChampa font
ContainsLaoDokChampaFont = True
Exit Function
End If
End If
Next i
' No Lao text in DokChampa font found
ContainsLaoDokChampaFont = False
End Function
Function IsLaoCharacter(unicode As Long) As Boolean
' Check if the Unicode value falls within the Lao Unicode range
If unicode >= &HE81 AndAlso unicode <= &HEDF Then
IsLaoCharacter = True
Else
IsLaoCharacter = False
End If
End Function
Sub ReplaceLaoTextWithReplacement(textRange As TextRange)
' Replace the Lao text with the desired replacement
' For example, replace Lao text with "Replacement Text"
textRange.Text = Replace(textRange.Text, "Lao Text", "Replacement Text")
End Sub
In this code, the ReplaceLaoTextWithFont
subroutine loops through all slides and shapes in the active presentation. It checks if the shape has text and if the text range contains Lao characters in the DokChampa font using the ContainsLaoDokChampaFont
function. If Lao text in DokChampa font is found, it calls the ReplaceLaoTextWithReplacement
subroutine to replace the Lao text with the desired replacement.
You can modify the ReplaceLaoTextWithReplacement
subroutine to specify the replacement text according to your needs.
Make sure to update the Unicode range values in the IsLaoCharacter
function if needed to match the specific Unicode range for Lao characters.
Note that this code assumes you have the DokChampa font installed on your system and available in PowerPoint.