PDA

View Full Version : [SOLVED:] Unicode Symbols - Display the Symbols in Word Document Convert the Unicode Numbers



dj44
02-22-2017, 05:06 PM
Hi folks,:)

good midweek.

I have always had this problem, but i always left it be, as i could cope with a few sysmbols, and it didnt seem so much of a problem.


Well today I've been hunting down some u symbols, and I tried to make them in to vba but unfortunatley I couldn’t work out how to do it.

Thes are unicode numbers, the display symbol has gone missing from the document so i was trying to replace them.

and i tried to google and get them back, but then it wouldnt work in word, i dont know why.

I searched everywhere in the symbol box but that didnt work either.
Then it was ASCII hex or decimal - so that was even more confusing.

These are some of the unicode numbers.
U+2326
U+2327
U+2328
U+2329

I am trying to output next to it the actual symbol - the nice looking friendly symbol.



Sub UnicodeSymbols()


Dim oRng As Word.Range
Dim oChr As Range
Dim oPara As Paragraph



For Each oChr In ActiveDocument.Range.Characters 'chrW(U+2326)



oRng.InsertAfter vbCr oChr
oRng.Collapse wdCollapseEnd

End Sub

' Greg Maxey Function -
Function GetSymbolValues(oRng) As String
Dim strFont As String
Dim lngANSI As Long, varHex As Variant
oRng.Select
With Selection
With Dialogs(wdDialogInsertSymbol)
strFont = .Font
lngANSI = .CharNum
varHex = Hex(lngANSI)
End With
End With
GetSymbolValues = lngANSI & "|" & strFont
lbl_Exit:
Exit Function

End Function

http://www.vbaexpress.com/forum/showthread.php?58534-Find-unique-characters



I just wanted to convert these numbers to the word display symbol

It would be such a relief if i can get the display symbol - i have searched every where today

is this at all possible?

To convert these u numbers to the actual symbol?

Paul_Hossler
02-22-2017, 06:11 PM
In not sure what you're trying to accomplish, but if you enter 2326 into the document and hit Alt-x it converts it to the appropriate Unicode character

So in the cursor is after the 2326 it will display the "X in a pointed box" symbol
18450
Try ChrW(2326) to insert using VBA

The VBA equivalent of Alt-X is



Sub Macro2()
Selection.TypeText Text:="2326"
Selection.ToggleCharacterCode
Selection.ToggleCharacterCode
End Sub

dj44
02-23-2017, 09:23 AM
Hi Paul,


I was able to make a nice input box with your help.


This code only does numbers though so 2334, 2326 etc


When I try alpha numbers
232B


It throws a type mismatch


But nearly there






Sub UnicodeToWordDisplaySymbol()


Dim oUnicodeNumber As String



'-- Placehholder INPUT BOX
oUnicodeNumber = InputBox("Enter the 4 Digit Unicode Number only : ")

If Len(oUnicodeNumber) = 0 Then ' If Nothing enetered Stop

Exit Sub

End If


Selection.TypeText Text:=ChrW(oUnicodeNumber)
Selection.ToggleCharacterCode
Selection.ToggleCharacterCode
End Sub

gmaxey
02-23-2017, 09:45 AM
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Selection.Range.InsertSymbol 2326, , True
Selection.Range.InsertSymbol 2327, , True
Selection.Range.InsertSymbol 2328, , True
Selection.Range.InsertSymbol 2329, , True
lbl_Exit:
Exit Sub
End Sub

Paul_Hossler
02-23-2017, 10:38 AM
Hi Paul,


I was able to make a nice input box with your help.


This code only does numbers though so 2334, 2326 etc


When I try alpha numbers 232B


It throws a type mismatch


But nearly there




Doing it that way, you have to make the string 'hex' into a number



Sub UnicodeToWordDisplaySymbol()
Dim oUnicodeNumber As String
Dim oUnicodeLong As Long


'-- Placehholder INPUT BOX
oUnicodeNumber = InputBox("Enter the 4 Digit Unicode Number only : ")

If Len(oUnicodeNumber) = 0 Then Exit Sub

oUnicodeLong = CLng("&h" & oUnicodeNumber)

Selection.TypeText Text:=ChrW(oUnicodeLong)

Selection.Range.InsertSymbol oUnicodeLong, , True ' Greg's code


End Sub

dj44
02-23-2017, 10:42 AM
Hi Greg,

thanks for the tip.

I still cant get over the last hurdle

the alpha numeric code

232B etc


Selection.Range.InsertSymbol chrW(232A), True

I've looked on line i'm not sure if i need to convert this to ASCII oh:doh: another job now

dj44
02-23-2017, 10:54 AM
Thanks Paul & Greg,

I can put the alpha numbers in the box and the friendly symbol is inserted now

That is a lot easier than me trying to search the symbol box which you cant you have to guess what the symbol is and

There is 4 options in word
ASCII
Hex
Character code
Decimal

its all too confusing for me -i dont know what it is, and i hate searching online for the symbol

but this input conversion box will help me

thank you
:)

Paul_Hossler
02-23-2017, 10:59 AM
Thanks Paul & Greg,

I can put the alpha numbers in the box and the friendly symbol is inserted now

That is a lot easier than me trying to search the symbol box which you cant you have to guess what the symbol is and

There is 4 options in word
ASCII
Hex
Character code
Decimal

its all too confusing for me -i dont know what it is, and i hate searching online for the symbol

but this input conversion box will help me

thank you
:)

Personally, I've always found the Alt-X way of entering symbols into a document an easy way to do it if I know the Unicode

dj44
02-23-2017, 11:37 AM
Paul,

You are correct

ALT + X works

Why didn't i know this before
:grinhalo:

oh well

I will write this shortcut down