How to change the font color of text in a textbox

2019-08-01 20:48发布

问题:

I want to try and change the font color of a text present in a textbox in Excel. I'm currently using python to access the object but am not being able to do so.

ActiveSheet.Shapes.Range(Array("Text1")).Select
Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "7"

With Selection.ShapeRange.TextFrame2.TextRange.Font.Fill
.ForeColor.RGB = RGB(255, 0, 0)

The code below is the VBA equivalent of assigning the number 7 to the textbox and changing the font color of the text to red. I've tried using various iterations and came across the following python code to perform the same process.

Currentsheet.Shapes.Range("Text1").TextFrame2.TextRange.Characters.Text= 7
Currentsheet.Shapes.Range("Text1").TextFrame2.TextRange.Font.ForeColor.RGB('255','0','0')    

The first part of the code works and I can assign the value 7 to the textbox. However, I am unable to assign the font color to red. Any help in this regard would be appreciated.