Getting the ansi value

K

Kamur

Hello,

When I Show bookmarks on the document, on a particular line, I can see
something weird..a special character. Looks like a dot. But is different
from normal periods. So, I wanted to know if there is a way to select that
particular bookmark and find the ansi value of that bookmark character?? Any
suggestions.

Thanks
 
L

Larry

This macro will do it.



Sub CharacterCode()

' Displays a message box with the ANSI code for the selected
character(s).
' Will work on next character is there is no selection.

If Selection.Characters.Count < 2 Then
MsgBox Asc(Selection.Text), , "Character Code"
Else

' If Selection is two characters are more, displays message box with
' character code for all the selected characters.

S1$ = "Because the selected text contains"
S2$ = " characters, not all of the ANSI values will be displayed."
'S3$ = "ANSI Value ("
S3$ = "Character Code ("
S4$ = " characters in selection)"
S5$ = " character in selection)"
S6$ = "Text must be selected before this macro is run."
S7$ = "ANSI Value"
'S7$ = "Character Code"
Dim strSel, strNums, LastFourChar As String
Dim iPos As Integer
strSel = Selection.Text
If Len(strSel) > 0 Then
For i = 1 To Len(strSel)
strNums = strNums + Str(Asc(Mid(strSel, i)))
Next i
strNums = LTrim(strNums)
If Len(strNums) > 255 Then
LastFourChar = Mid(strNums, 252, 4)
strNums = Left(strNums, 251) + Left(LastFourChar, 4 - InStr(" ",
LastFourChar))
MsgBox S1$ + Str(Len(strSel)) + S2$
End If
If Len(strSel) = 1 Then S4$ = S5$
MsgBox strNums, 0, S3$ + LTrim(Str(Len(strSel))) + S4$
Else
MsgBox S6$, 0, S7$
End If
End If

End Sub
 
T

Theo van der Ster

Hi Kamur,

This should do it. Select the character and run the following code:

MsgBox Asc(Selection)

Regards,
Theo
 
M

Martin Seelhofer

Hi there

Another possibility is to simply use the immediate window in the
visual basic editor:

1. start the vb editor (ALT + F11)
2. set cursor in the immediate window (CTRL + G)
3. write the following (including the question mark): ? Asc(Selection)
4. Press enter and the value will be displayed.


Cheers,

Martin
 
K

Klaus Linke

BTW, I'd always use AscW instead of Asc.
Word uses Unicode, and Asc won't display the proper code for characters
outside the old Windows code page.

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top