Runtime macro Libre Calc oCell.setString U+1F400

To pass a symbol U+**** (Four digits) can be done using ChrW(2222) and Option VBASupport 1.
But how to pass symbols like U+1F400(see UTF8 here (Unicode/UTF-8-character table - starting from code position 1F400)

You can use the UNICODE() and UNICHAR() functions of the Calc in your macro (even if the macro will work in other application…):

Function HighUchar(ChCode as long) as string
dim oFunctionaccess
dim arg as Variant
   oFunctionAccess = createUnoService( "" )
   arg =array(ChCode)
HighUchar = oFunctionAccess.CallFunction("UNICHAR",arg)
End function

This function can convert the upper Unicode character codes to an Unicode character. (without the VBA option)

Thanks. The function works for Hex : HighUchar(&HF09F) and for decimal: HighUchar(55357). But returns Error for Low Unicode: HighUchar(u99C) and HighUchar(U+1F415).

It seems that the Calc function (or the Basic) recognizes the u99C and U+1F415 as some strings but not as numeric values.

Use the pure hexadecimal values/format: &H99C &H1F415 or or their decimal equivalent. They will be recognized as numeric values. Or improve the function with some conversion routines.

The ChrW() function produces characters of the Unicode Basic Multilingual Plane (BMP) in UCS2 encoding with values in the interval [0,65535]. However, knowing that the LibreOffice internal string representation uses the UTF-16 encoding to be able to handle all Unicode characters (where for the BMP characters UTF-16 code units are equal to UCS2 code units) you can concatenate two “fake” ChrW() calls to form a valid UTF-16 code units sequence. In this case U+1F400 in UTF-16 is D83D DC00 so

print ChrW(&HD83D) + ChrW(&HDC00)

prints the RAT character.

Thanks. It works. Needed ‘Option VBASupport 1’ for ChrW.

Yes, of course, as stated in ChrW help.