Search code examples
ms-officevstopowerpointoffice-interop

Set color for future text


In PowerPoint, when I am inside a text frame and I have not selected any text and I am then setting the text color, it does not change the color for any currently visible text. It does however change the text color for the text that I will enter next.

I want to achieve the same using the office API.

I have tried ActiveWindow.Selection.TextRange.Font.Color.RGB = RGB(255, 128, 0), but this sets all text of the current text frame to this color.

What is the right way to achieve what I am trying to achieve?


Solution

  • Have a go with something along these lines:

    With ActiveWindow.Selection.ShapeRange(1).TextFrame.TextRange
        With .Characters.InsertAfter(" ")
            .Font.Color.RGB = RGB(0, 255, 0)
        End With
    End With
    

    This inserts a space at the end of the currently selected shape's text and sets the space to the desired color. Any text added after that will be the same color as the space character.