Search code examples
vbacompowerpointtextrange

Simulating "Increase Font Size" in PowerPoint VBA


In PowerPoint, if I've selected text with multiple sizes, I can hit the "Increase Font Size" or "Decrease Font Size" to have each TextRange grow/shrink by one "step" :

Increase/Decrease Font Size icons

I almost have a manual solution as follows:

Sub GrowText(ByRef t_range as TextRange)
    Dim sub_range as TextRange
    For Each sub_range in SplitBySizes(t_range)
        sub_range.Font.size = NextSize(sub_range.Font.size)
    Next sub_range
End Sub

The NextSize function uses a static array (8, 9, 10, 10.5, 11, 12, 14, 16, 18, 20, 24, 28, 32, 26, 40, 44, 48, 54, 60, 66, 72, 80, 88, 96) to find the next biggest font size, and I know how to implement it. What I don't know how to do is implement SplitBySizes, which should return an Array of TextRange objects with text having the same size. Is there a way of doing that without looping character by character? I'm eventually going to move this code into a COM application.


Solution

  • Try something based on this instead:

    For each sub_range in t_range.Runs
    

    Each bit of text with formatting different from the previous text is a Run.