what is the actual ascii code for a inserted symbol?

As far as I know

  • there is no simple way to get the character’s code point or font name directly using any of the properties of the Selection or Range

  • In this situation, Word always uses the code point 40 (“)”), and internally, it does does store the name of the font you specified and a Unicode codepoint (e.g. U+F052 for the checked box).

Two things you can do. If the character is not 40, assume it already has the correct codepoint (although I am not certain about that). But if not,

  • retrieve the .XML or .WordOpenXML of the Selection or Range and look for the relevant element, e.g. ><w:sym w:font="Wingdings 2" w:char="F052"/> in both the old-style .XMLand the newer .WordOpenXML. You could either search for the text <w:sym and look for the font and codepoint in the following text, or “do it properly” using an XML parser. In that case, it may be useful to know that F052 either means “the Unicode character with code point F052, or it means “it’s F000 + the code point in the original character set”, i.e. Wingdings 2 in this case.

e.g. one way would be to make a reference in the VB Editor’s Tools-References to the Microsoft XML library (in this case 6.0) and use code along these lines:

Sub getCharFontAndCodepoint()
Dim xdoc As MSXML2.DOMDocument60
Dim xSymNodes As MSXML2.IXMLDOMNodeList
Set xdoc = New MSXML2.DOMDocument60
xdoc.async = False
If xdoc.LoadXML(Selection.XML) Then
  xdoc.SetProperty _
    "SelectionNamespaces", _
  Set xSymNodes = xdoc.SelectNodes("//w:sym/@w:font")
  If xSymNodes.Length > 0 Then
    Debug.Print xSymNodes(0).NodeValue
  End If
  Set xSymNodes = xdoc.SelectNodes("//w:sym/@w:char")
  If xSymNodes.Length > 0 Then
    Debug.Print xSymNodes(0).NodeValue
  End If
End If
Set xSymNodes = Nothing
Set xdoc = Nothing
End Sub
  • or, if you only need the codepoint, copy the character and use paste special to paste it using the Unformatted Unicode Text format, e.g.

     Selection.PasteSpecial link:=False, DataType:=22 ' There does not seem to be a named enum for this particular format
     Selection.MoveLeft Unit:=WdUnits.wdCharacter, Count:=1, Extend:=WdMovementType.wdExtend
     Debug.Print Hex(AscW(Selection))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top