Consulting

Results 1 to 9 of 9

Thread: Unicode Symbols - Display the Symbols in Word Document Convert the Unicode Numbers

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Unicode Symbols - Display the Symbols in Word Document Convert the Unicode Numbers

    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?
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    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
    Capture.JPG
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    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
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  4. #4
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,339
    Location
    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
    Greg

    Visit my website: http://gregmaxey.com

  5. #5
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Quote Originally Posted by dj44 View Post
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  6. #6
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    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 another job now
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  7. #7
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    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
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Quote Originally Posted by dj44 View Post
    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
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  9. #9
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Paul,

    You are correct

    ALT + X works

    Why didn't i know this before


    oh well

    I will write this shortcut down
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •