Macro for changing color of individual characters in a cell in calc?

Hi.
I’m trying to write a macro that will change the color of individual characters in calc, depending on which letter they are.
I can change the color for the entire cell’s text, no problem. But I can’t figure out how to manipulate the color of just the i-th char. (it is very easy to manually color just a subset of the string in a cell, so I know calc is able to handle cells with multiple colors).

I’d appreciate any help.

Thanks