+ Reply to Thread
Results 1 to 8 of 8

VBA code to insert unicode symbol.

  1. #1
    Registered User
    Join Date
    06-05-2018
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    4

    VBA code to insert unicode symbol.

    I'm trying to programmatically (VBA) insert the Triangular Flag symbol, Character code: 1F6A9, converted to Decimal is 128681. It can be found in Symbols > Font: Segoe UI Symbol > Subset: Extended Characters - Plane 1 > about 24 rows from the bottom.

    I've tried variations of Chr(), ChrW(), AscW; with and without "&H" and also tried converting to binary
    e.g.:
    [A1] = ChrW(128681)
    [A1] = ChrW(&H1F6A9)
    [A1] = AscW(128681)
    [A1] = AscW(&H1F6A9)
    [A1] = Asc(1.1111011010101E+16)

    None seem to give me a flag. Sometimes they they result in "49" though.

    Any ideas?
    Thanks.

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Exclamation Re: VBA code to insert unicode symbol.


    Your decimal conversion can't exist with the function ChrW like you can check in VBA help …

  3. #3
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA code to insert unicode symbol.


    The easy kid way to find out the code character :
    just insert the expected character within a cell then on VBE side just display its code via the VBA function AscW, could be a negative value ...

  4. #4
    Registered User
    Join Date
    06-05-2018
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    4

    Re: VBA code to insert unicode symbol.

    Didnt work for me, but thanks for the suggestion.
    I tried:
    =DecodeAscW("flagSymbol")
    in a cell, which gave 55357, but in VBA:
    [A1]=AscW(55357)
    results in 53.

    I also decoded the flag symbol to -10179 somehow, but that's as far as I could get, trying other functions with that value.

  5. #5
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA code to insert unicode symbol.


    As the kid way can't fail so your bad according to AscW VBA help - a must read ‼ - which returns the first character numeric code value !
    So once your get the code via AscW then to use a char according to its code just use the VBA function ChrW …

  6. #6
    Registered User
    Join Date
    06-05-2018
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    4

    Re: VBA code to insert unicode symbol.

    I think the problem is that ChrW just doesn't work on all the values it is supposed to work on (0 to 65535). If you run the code below to print every symbol in a separate cell, you'll see it returns most of them, but there are sections where it just returns squares with "?"s in the middle. And the symbol I want (55357) just happens to be in one of the sections of squares/?'s. So I guess it can't be done with ChrW.

    Sub print_all_symbols()
    For j = 1 To 65
    For i = 1 To 1000
    n = n + 1
    Cells(i, j) = ChrW(n)
    Next
    Next
    End Sub

    I did think of 2 work arounds: 1) insert a flag symbol in a cell that hopefully won't be seen or edited, then use copy-paste code. (not very elegant, and could be compromised).
    2) use code to set the cell to a formula that ultimately displays the flag symbol, even though the cell text is not the symbol itself. I opted for this:
    [A1].Formula = "=UNICHAR(""128681"")"
    Last edited by ads4go; 11-13-2022 at 03:28 AM.

  7. #7
    Registered User
    Join Date
    04-27-2017
    Location
    Italy
    MS-Off Ver
    Office 2013
    Posts
    4

    Re: VBA code to insert unicode symbol.

    Hi all,
    try this code:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: VBA code to insert unicode symbol.


    Quote Originally Posted by ads4go View Post
    I think the problem is that ChrW just doesn't work on all the values
    As ChrW well works whatever the value according to the specific font so
    do not forget to set the same font to the cell where you allocate the character according to its code !

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. how to use insert symbol panel to search & insert a symbol into a textbox in a userform?
    By blue_clouds_mountain in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2021, 06:23 PM
  2. [SOLVED] VBA to insert symbol
    By Undo in forum Word Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2021, 10:16 AM
  3. [SOLVED] Emoji Unicode VBA replace code with icon in cells
    By asitiz in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-15-2018, 08:48 AM
  4. Insert a symbol
    By jobykuriakosejk in forum Excel General
    Replies: 2
    Last Post: 07-19-2014, 03:04 AM
  5. Insert a symbol
    By Lloydee in forum Excel General
    Replies: 3
    Last Post: 08-12-2007, 08:34 AM
  6. [SOLVED] Insert symbol
    By Frank E in forum Excel General
    Replies: 3
    Last Post: 06-23-2006, 09:50 AM
  7. Replies: 2
    Last Post: 05-02-2005, 08:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1