Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

excel - Padlock symbol through vba

Is it possible to print a padlock symbol (open & closed) in a cell with Chr(), ChrW() or something similar through VBA?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It seems that Excel stores special chars as UTF-16. As long as you have a code that fits within 16bit, it's easy: Just convert the code using function ChrW. For example, the code for an alarm clock is U+23F0, so you can write ActiveCell.Value = ChrW(&H23F0) and you get your alarm clock (the prefix &H defines a hexadecimal number).

However, when you have characters that doesn't fit into these 16bit, you have to figure out the UTF-16 codes and concatenate them. The locks I found are U+1F512 and U+1F513, and their UTF-16 representatives are 0xD83D 0xDD12 resp. 0xD83D 0xDD13. So you write something like

ActiveCell.Value = ChrW(&HD83D) & ChrW(&HDD12)

Of course, you need to set a font to the cell that supports these characters.

I found http://www.fileformat.info/info/unicode/char/search.htm helpfull to find matching characters. If you have already a character and you can paste it into a cell, you can use the code I've written in this answer: https://stackoverflow.com/a/55418901/7599798


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...