Results 1 to 4 of 4

Thread: Solved: Text color in a text box not sticking

  1. #1

    Solved: Text color in a text box not sticking

    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(msoTextOrientationHorizontal, 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
        .TextFrame.TextRange.Select
        .Fill.Visible = msoTrue
        .Fill.Solid
        .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?

    Thanks!
    Last edited by Aussiebear; 04-28-2023 at 01:48 AM. Reason: Adjusted the code tags

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,096
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    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!

  4. #4
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,096
    Location
    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.
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •