Can anyone explain how to insert emojis to VBA Excel?

匆匆过客 提交于 2021-01-24 11:26:46

问题


In VBA Excel to print " & Chr(34) & " is used to define ". I have searched and it said 34th character is ", as per this website.

In same way for 👍 Thumbs Up Sign the code is

👍 👍

I have tried:

" & Chr(#128077) & "  
" & Chr(128077) & "  
" & Chr(#x1f44d) & "
" & Chr(x1f44d) & "

But it says error as a Syntax error or Expecting ) or Invalid Argument

Can anyone suggest me the solution


回答1:


In Excel, characters are stored using Unicode UTF-16. "Thumbs up" corresponds to the Unicode character U+1F44D, encoded as follows:

in UTF-16 (hex) : 0xD83D 0xDC4D (d83ddc4d)

in UTF-16 (decimal) : 55357 , 56397

All those characters which are not the classic latin characters (ASCII) are to be handled with chrW and ascW.

So, in your case

ChrW(55357) & ChrW(56397)
or
ChrW(&HD83D) & ChrW(&HDC4D)

would produce thumbs up. Also note that you won't get that in the VBA IDE. You will have to put it in a worksheet to see it.

Clarification

' Puts a thumbs up symbol in A1
ActiveSheet.Range("A1").Value = ChrW(55357) & ChrW(56397)

' Will not produce a thumbs up symbol, since VBA can't handle it
Debug.Print ChrW(55357) & ChrW(56397)

' Will not produce a thumbs up symbol, since VBA can't handle it
MsgBox ChrW(55357) & ChrW(56397)

HTML
If you want the thumbs up to be in HTML, then do like this:

HtmlString = "<p>something something &#128077;</p>"
Print #1, HtmlString ' <-- replace with your output method

(&#128077; or &#x1f44d;)



来源:https://stackoverflow.com/questions/55195005/can-anyone-explain-how-to-insert-emojis-to-vba-excel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!