Reputation: 21
I have a question regarding the win32com bindings for excel. I set up early bindings and followed some examples from the "Python Programming on Win32" book from O'Reilly.
The following code works fine:
book2.xlApp.Worksheets('Sheet1').Cells(1,1).Font.ColorIndex = 1
book2.xlApp.Worksheets('Sheet1').Cells(1,1).Font.ColorIndex = 2
It changes the font color of the whole cell according to the number. However this does not work:
book2.xlApp.Worksheets('Sheet1').Cells(1,1).Characters(start,length).Font.ColorIndex = 1
I get the following callback:
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: Characters instance has no __call__ method
However in Excels VBA the code works. Can anybody point me to the solution? I really need to change parts of a string in an excel cell.
Thank you very much.
Upvotes: 2
Views: 3449
Reputation: 97301
use GetCharacters:
Cells(1,1).GetCharacters(start,length).Font.ColorIndex = 1
Upvotes: 6