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

◇◆丶佛笑我妖孽 提交于 2019-12-24 14:03:29

问题


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.

来源:https://stackoverflow.com/questions/31708983/how-to-change-the-font-color-of-text-in-a-textbox-in-excel-using-python-in-win

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!