0

In PowerPoint I have a TextRange object and I would like to set the fill color (not the font color).

I know given a shape I can set via Fill.ForeColor, but what about for a TextRange object?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
kimon
  • 2,481
  • 2
  • 23
  • 33

1 Answers1

2

You can't 'fill' a TextRange object but if you are trying to fill the text box that contains the TextRange then you fill the shape which is two parents above the TextRange object.

e.g.

Dim oShp as Shape
Set oShp = ActivePresentation.Slides(1).Shapes(1)
' Fill the text with red
oShp.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(255,0,0)
' Fill the text box with green
oShp.Fill.ForeColor.RGB = RGB(0,255,0)
Jamie Garroch - MVP
  • 2,839
  • 2
  • 16
  • 24
  • Almost-- what I want to do is fill the background color, but only behind the text in the TextRange, not the entire text box – kimon Nov 13 '15 at 20:47
  • 1
    As Jamie says, you can't do that. The closest you can get is to add a rectangle of the color you want and sized and placed via the text range's BoundingBox properties. – Steve Rindsberg Nov 14 '15 at 17:45
  • But I could do it by hand by selecting the text and then changing the background color of that selection. Is there no way to do that same thing via the API? – kimon Nov 14 '15 at 17:48
  • 1
    Ok...I guess I was wrong. I tried to do it by hand, but there does not seem to be a way to change the background of just the selected text... – kimon Nov 14 '15 at 17:53
  • Right. You can highlight text in Word to get this effect, but not in PPT. For small amounts of text, sometimes people will do exactly that: create it in Word then copy/paste into PPT. If you want to try the other method I suggested, there's some example code here: http://www.pptfaq.com/FAQ00776_Highlight_text_in_PowerPoint.htm – Steve Rindsberg Nov 15 '15 at 17:01