View Full Version : Solved: Text color in a text box not sticking

08-08-2007, 12:27 PM
Hello all,

I have a macro in PPT that I've created to give me a text box with a white background, red border, and black text centered. Here is the code:

Sub create_red_box()

Dim oTextBox As Shape
Dim strText As String

strText = "test"

Set oTextBox = ActiveWindow.Selection.SlideRange.Shapes.AddTextbox(msoTextOrientationHoriz ontal, 100, 150, 200, 30)

With oTextBox
.Line.Visible = msoTrue
.Line.ForeColor.RGB = RGB(255, 0, 0)
.Line.BackColor.RGB = RGB(255, 255, 255)
.TextFrame.TextRange.Text = strText
.TextFrame.TextRange.Font.Color.RGB = RGB(0, 0, 0)
.TextFrame.TextRange.Font.Name = "Arial"
.TextFrame.TextRange.Font.Size = "16"
.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(255, 255, 255)
.Fill.Transparency = 0#
.Line.Weight = 2#
End With

End Sub
It works fine.

I add the word "test" to the box because if I don't, the text will not stay black (as defined in the macro). Instead, it turns red. I select the word near the end of the macro so that I can just start typing and it will replace the word "test" with whatever I type. This text will be black. So this little workaround gives me what I need.

The problem that I'm having is that if I *paste* text in from another source, the pasted text is red. I am copying text from a Word document. In the Word document, the text is black. I am careful not to select the paragraph mark in Word when I select the text.

Is there a setting I can add to the macro that will ensure all text in the text box will be black? I *thought* I had done that in the macro as you see it above, but apparently not.

Any thoughts?


John Wilson
08-08-2007, 11:34 PM
Both these problem (the initial need for some text and the red text paste color) are because Powerpoint defaults to the size and color set in the defaults which I guess is red. To fix this draw a shape (not a text box) add some text and set it to the size and colour you need > right click and set autoshape defaults.

08-09-2007, 05:38 AM
I tried drawing a shape and setting the defaults, but that didn't do it. I'm sure I did something wrong. But when I drew a text box, set the text to black, and set that as the default, it seems to have worked. Thanks!

John Wilson
08-09-2007, 06:12 AM
The problem with using a text box is that subsequent SHAPES will have no fill / line. You may need to draw a shape and set the fill and line defaults, this wont affect the text.