views:

36

answers:

2

I need to append programmatically (VBA/VSTO) several special symbols (e.g., smileys) into text in a TextRange in PowerPoint 2007.

I can insert a symbol using:

With ActiveWindow.Selection.TextRange .Text = "sometext" Call .Characters(.Characters.Count + 1).InsertSymbol("Arial", 65, MsoTriState.msoTrue) End With

Unfortunately, when I try to insert several symbols one after the other with different fonts, only the last one shows correctly and the previous ones show like empty squares.

How can I insert several symbols from different fonts? Perhaps there is a way to create a new Run for each symbol?

+1  A: 

Create a new TextRange object for each .InsertSymbol.

Dim tr1 As TextRange
Set tr1 = ActiveWindow.Selection.TextRange
tr1.InsertSymbol "Wingdings", 81
Dim tr2 As TextRange
Set tr2 = ActiveWindow.Selection.TextRange
tr2.InsertSymbol "Wingdings 2", 81
Otaku
A: 

Each InsertSymbol erases the contents of the TextRange, at least in my tests.

However, I found a way without InsertSymbol. Repeat for each symbol:

newRun.InsertAfter(character); // insert symbol character, and create a new Run

// set the "Other" font to the desired symbol font -

// important to use NameOther and not Name, otherwise special symbols such as Copyright

// will disappear if they are not present in the selected font

// (e.g., Wingdings does not have the Copyright symbol) newRun.get_Characters(newRun.get_Characters(-1, -1).Count, 1).Font.NameOther = symbolFontName;

Arie Livshin
`InsertSymbol` inserts at the end of a `TextRange`. If you have selected text, it will insert it at the beginning (effectively deleting the selected text and then inserting your symbol). The key is to not select any text - just place the cursor where you want it to be (like with `ActiveWindow.Selection.TextRange` where nothing is selected) and insert the symbol there.
Otaku
I am working on a hidden window, so I cannot use selections or cursor position.
Arie Livshin