2

I know the unicode to the lock symbol( ) is 128275

When I copy this symbol from the browser and paste into excel, it appears like this: lock symbol in Excel

When I try to insert this symbol using VBA using ChrW():

Range("b2").Value = ChrW(128275)
Range("b2").Text = ChrW(128275)

I get the error:

Run-time error '5': Invalid procedure call or argument

I expect that the function ChrW() is not capable of receiving any value greater than &HFFFF which the lock symbol does exceed.

Is there a way to insert the lock symbol (using VBA) the same way Excel itself handles it (even though the coloring scheme is totally different)?

And is it possible to insert the symbol using C# and EPPlus nuget package?

Ahmad
  • 12,336
  • 6
  • 48
  • 88

1 Answers1

3

For symbols greater than 16 bits, build the symbol like:

Sub marine()
    Range("b2").Value = ChrW(&HD83D) & ChrW(&HDD12)
End Sub

enter image description here

Gary's Student
  • 95,722
  • 10
  • 59
  • 99
  • Can you elaborate on how this works? How do I calculate those two codes? – Toddleson Jul 14 '21 at 12:32
  • 1
    @Toddleson You need to know the UTF-16 code for that. See my answer in the question here: https://stackoverflow.com/questions/56004536/padlock-symbol-through-vba. The mentioned page https://www.fileformat.info/info/unicode/char/search.htm still works – FunThomas Jul 14 '21 at 12:36
  • Fyi There's a whole bunch of further alternatives (worksheet.function `Unichar`, API, xml, html approaches); see [Get Unicode Characters with charcode values greater hex ffff](https://stackoverflow.com/questions/56008191/get-unicode-characters-with-charcode-values-greater-hex-ffff) @Garys-Student – T.M. Jul 14 '21 at 17:12