Inserting symbols into text in PowerPoint 2007 using VBA

半世苍凉 提交于 2019-12-11 05:07:37

问题


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 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;



回答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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!