How to change font color of text in textbox in Excel using Python in win32com.client

I want to try changing the font color of the text present in a text box in Excel. I am currently using python to access an object, but cannot do this.

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 following is the VBA equivalent code to assign the number 7 to the text field and change the font color of the text to red. I tried using different iterations and came across the following python code to execute 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 text box. However, I cannot set the font color to red. Any help in this regard would be appreciated.

+1

All Articles