Share via

Word VBA Change Font Color in Inserted Shape

Anonymous
2019-01-29T19:25:41+00:00

Hi, I create a triangle shape in a document and add a number to that shape.  I cannot figure out how to programmatically change the text effects of the inserted number to black.  When I add text to shapes word is defaulting to white font color.  I have to go into text effects and even though the font fill color shows black, the text color is white.  After highlighting the white text, I have to choose black (even tho black is the current selection) to get the font to change to black.  Here's the code I have that is not making the change to black programmatically.

  RevNumber = InputBox("Rev Number?")

    Set TriangleNew = ActiveDocument.Shapes.AddShape(msoShapeIsoscelesTriangle, 565, RangeStart - 5, 19, 19)

    TriangleNew.Name = "RevTriangle " & Rnd(99999)

    With TriangleNew

        .Fill.Transparency = 1#

        .TextFrame.TextRange.Font.ColorIndex = wdBlack

        .TextFrame.TextRange = RevNumber

        .TextEffect.FontSize = 8

        .Fill.Visible = msoFalse

        .TextFrame.AutoSize = True

        .TextFrame.WordWrap = True

        .Line.Visible = msoFalse

        .ZOrder msoSendToBack

    End With

Any ideas?  I assume I could just create a shape in normal.dotm and set that as default but this is a problem company wide and I need the macro to accomplish this for me for these shapes on everyone's station. 

thanks for the generous help!

Cindy

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2019-01-30T18:27:51+00:00

If you're single-stepping through the code with F8, all I can tell you is that the VBA editor sometimes does that. The jump to the end of the macro that's visible to you may or may not indicate correctly whether the "skipped" statements are being executed. Can you tell from what the final image looks like? If not, maybe you can check it by using the Immediate window (Ctrl+G) to ask for one or more of the "skipped" values, for example

Print ActiveDocument.Shapes(1).TextFrame.AutoSize 

which may print False if that statement was really skipped or True if it executed.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2019-01-30T03:54:25+00:00

I'm using Word 2019 at the moment, which is supposed to be the same as a build from last fall of Word 2016. I had tested in a .docm file, but now I've saved it as a .doc (Compatibility Mode) and the result is the same. I'm seeing both the number and the triangle as black. No white, no blue.

Is it possible that at some point you changed the font color and line color and set that as the default shape format for the document? What do you get if you start with a new blank document?

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

Answer accepted by question author

Jay Freedman 207.7K Reputation points Volunteer Moderator
2019-01-29T21:11:31+00:00

Setting .TextFrame.TextRange.Font.ColorIndex = wdBlack works for me; it doesn't appear as white (although it's mostly not visible until the AutoSize executes).

What doesn't work is the .TextEffect.FontSize = 8 statement, which gets a runtime error that TextEffect isn't available for the Shape object. Instead, you need TextFrame.TextRange.Font.Size = 8. Also, setting the .Line.Visible = False makes the triangle disappear and leaves only the number, which means there's little point to using a shape at all. Finally, any number in the text frame will be off-center in the shape unless the width is at least 36 points.

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2019-01-30T00:23:26+00:00

    Sorry, I didn't realize the image wouldn't appear.  I see a blue triangle. 

    Cindy

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2019-01-30T00:22:31+00:00

    Jay, using the code from above, this is what I see:

    I am using Word 2016 in compatibility mode if that makes a difference.  I have changed my code to match what you recommended and am still getting the same result with the font color being white.  I will also need to change the shape/textbox margins so the number will appear correctly.  Even though the line.visible is false I still get the solid blue lines.

    My first attempt was to select the new triangle and that's where I used the text effects.  I neglected to switch it back before I sent the code out.

    thanks,

    Cindy

    Was this answer helpful?

    0 comments No comments