PowerPOint Add-In - Insert text in the sentence

Add-in Express™ Support Service
That's what is more important than anything else

PowerPOint Add-In - Insert text in the sentence
Preserving fonts and colors in the sentence while inserting text 
Leon H H




Posts: 17
Joined: 2010-04-06
I have PP Add-In slide with the sentence (TextRange):

"This is my test"

I need to insert the word "second" in red color after the word "my" and all other words must preserve their colors.

How do I go about it? I'd rather see code in C# (but will take VB if you must)
Posted 14 Jul, 2022 20:13:13 Top
Andrei Smolin


Add-in Express team


Posts: 18338
Joined: 2006-05-11
Hello Leon,

Calling PowerPoint.TextRange.InsertAfter() produces a PowerPoint.TextRange where you get the Font property that returns a PowerPoint.Font object: set its Color as required.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 15 Jul, 2022 03:35:58 Top
Leon H H




Posts: 17
Joined: 2010-04-06
This is definitely not the answer I am looking for.
Please read my question again - it is way more complex problem:
I have a sentence where the words have different color.
I need to insert a word with my own different color and still preserve all the original words colors in the sentence.

When you use TextRange.InsertAfter you are inserting text at the end of the range, not the middle, and you get TextRange object returned to you that is what you inserted. So, I agree that you can color it... But what about the rest of the sentence? If you add it to the above range it will get the color of the text you just inserted - but I need to preserve original colors. It could work if original colors woudl be just one color but different words are colored differently...

Another example:
ORIGINAL TextRange: This is the example of mine

I need to insert text "second" with red color after "is the"
so it will be:
This is the second example of mine

And it should be a single TextRange.
I simply cannot find either methods or Properties of the TextRange that will allow me to produce that...
Would you please try to create the code for this?
Posted 16 Jul, 2022 19:57:07 Top
Andrei Smolin


Add-in Express team


Posts: 18338
Joined: 2006-05-11
Leon,

Leon H H writes:
I need to insert a word with my own different color and still preserve all the original words colors in the sentence.


I don't understand why you refer to the sentence. Calling InsertAfter() produces a TextRange object containing the text just inserted; when you modify the color of the font of that TextRange object, the change only applies to that text range, not to the whole sentence.

Leon H H writes:
And it should be a single TextRange.


What do you mean by this? InsertAfter() returns a single TextRange object.

Leon H H writes:
Would you please try to create the code for this?


Please provide a test project that works wrongly; send it to the support email address. I'll test it on my side.

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 18 Jul, 2022 08:59:01 Top
Leon H H




Posts: 17
Joined: 2010-04-06
Originally PPTextRange includes original sentence: "This is the example of mine"
PowerPoint.TextRange tr = PPTextRange.InsertAfter("second"); inserts the "second" after all the text included in PPTextRange.

That is, tr is the TextRange that contains "second".
And PPTextRange now is: "This is the example of mine second".

But that's not what I am trying to achieve. I need to insert "second" after "This is the " and with all that to preserve colors...
Posted 18 Jul, 2022 15:31:44 Top
Andrei Smolin


Add-in Express team


Posts: 18338
Joined: 2006-05-11
Hello Leon,

Leon H H writes:
But that's not what I am trying to achieve. I need to insert "second" after "This is the " and with all that to preserve colors...


My previous examples - see Positioning cursor in PowerPoint Add-In - demonstrated the way you use to insert "second" after "This is the". I assume they preserve colors. To set the color of the inserted range, get the TextRange object that InsertAfter() returns and set TextRange.Font.Color.

Can you send me a sample project that works wrongly for you? Is this possible?

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 19 Jul, 2022 03:51:37 Top
Andrei Smolin


Add-in Express team


Posts: 18338
Joined: 2006-05-11
Hello Leon,

Did you solve this?

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 20 Jul, 2022 04:24:58 Top
Leon H H




Posts: 17
Joined: 2010-04-06
Yes, it partially resolved my issue. Managing/tracking the changes is the heart of my problems, especially, multiple deletions (and insertions)
Posted 21 Jul, 2022 13:01:48 Top
Andrei Smolin


Add-in Express team


Posts: 18338
Joined: 2006-05-11
Thank you for letting me know!

Regards from Poland (CEST),

Andrei Smolin
Add-in Express Team Leader
Posted 22 Jul, 2022 02:10:44 Top