问题
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:
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 newRun
- set the "Other" font to the desired
symbol font - important to use
NameOther
and notName
, 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;
回答2:
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
回答3:
It took me a lot of time and effort to solve this issue. Then I bothered and posted the solution.
Someone is busy "Voting-Down" my questions/answers without bothering to understand the complexity nor the solutions.
来源:https://stackoverflow.com/questions/4025731/inserting-symbols-into-text-in-powerpoint-2007-using-vba