Discussion Locked

Unicode in MS Word

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

How can I retrieve UNICODE symbol from MS Word document throu VBA? For example, I insert times symbol ('x') using menu Insert/Symbol. How get it in follow code:

For Each ch In Selection.Characters
if ch = "?" then MsgBox "It's here!"
Next

3 replies

by peyison

Try using the AscW() function. This will return the character code of the character you pass it. (If you're just using the plain ASCII character set you can use Asc(). AscW() is for Unicode.)

First, figure out the character code of the characteryou're looking for by selecting the character and calling a function like:

msgbox "code = " & AscW(Selection.Characters(1).Text)

Then, use that code in your condition:

iCharCode = 40 ' (or whatever your code was)

For Each ch in Selection.Characters
If AscW(ch) = iCharCode then Msgbox "It's here"
Next

Hope this helps.

This discussion is closed to new replies.