Results 1 to 4 of 4

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

Posting Permissions

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