In the process of generating a slide via VBA in powerpoint, I need to insert a "Wingdings symbol" within a generated text which is a comparison of two values. I made this method which is working exactly as I want
Sub formatDifference(header As String, old As Integer, now As Integer, txt As TextRange)
Dim diff As Integer
diff = old - now
With txt
If (diff > 0) Then
.InsertSymbol "Wingdings", getArrowCharCode("down")
' getArrowCharCode is a custom function to get the
' char code as an Integer
ElseIf (diff = 0) Then
.InsertSymbol "Wingdings", getArrowCharCode("right")
Else
.InsertSymbol "Wingdings", getArrowCharCode("up")
End If
.InsertBefore header & now & " (" ' <-- note this line
.InsertAfter " " & Abs(diff) & ")"
End With
End Sub
The formatDifference Sub is basically just adding a bullet point line in the text (in the example below, the procedure is called 4 times before I add a non-bullet text).
What I don't understand is when I initiate the text with some text and then use the InsertSymbol method, the text seems to actually get replaced instead of having the symbol appended at the end. Here's an example of the different code :
Sub formatDifference(header As String, old As Integer, now As Integer, txt As TextRange)
Dim diff As Integer
diff = old - now
With txt
.InsertAfter header & now & " (" ' <-- line moved here
' it doesn't matter if I use
' .Text = "initial text"',
' it will do the same thing
If (diff > 0) Then
.InsertSymbol "Wingdings", getArrowCharCode("down")
ElseIf (diff = 0) Then
.InsertSymbol "Wingdings", getArrowCharCode("right")
Else
.InsertSymbol "Wingdings", getArrowCharCode("up")
End If
.InsertAfter " " & Abs(diff) & ")"
End With
End Sub
And here's a comparison of the two results I get from the codes above (in the same order) :
My understanding of the InsertSymbol method was that it would insert the symbol at the end of the last paragraph, but it does not look like it... Is my second example faulty or did I misunderstand the description of the method?
P.S. Note: the header parameter was holding the carriage return and line feed characters which is why the second capture has all the points on the same line since that first part seems to be replaced.

Documentation of InsertSymbol implementations
Microsoft Word's Range.InsertSymbol and Selection.InsertSymbol implementations are described as:
Microsoft Publisher's TextRange.InsertSymbol implementation is described as:
And then there are Office TextRange2.InsertSymbol and PowerPoint TextRange2.InsertSymbol methods described as:
With this in mind, the PowerPoint documentation of the TextRange.InsertSymbol implementation is a bit inaccurate including a wrong explanation ("after the first sentence") of the included code example.
InsertSymbol after TextRange
If you want to get the symbol inserted after the provided
TextRange, I suggest following wrapper function:It distinguishes two cases:
vbCR(Chr(13), carriage return, CR), the symbol is added before the CR (the CR is replaced by the new symbol and added afterwards again).Test
The function can be tested for whole textframes, paragraphs or characters by this: