How to create own panel with icons of special symbols?

A

avkokin

Hello.
I wonder, if there is a possibility to create own toolbar (panel) with
the icons of special symbols for quick insert they into document? I
want to have the possibility to add (and remove) on this toolbar
(panel) only those symbols which I need.
Thank you very much.
 
K

Klaus Linke

avkokin said:
Hello.
I wonder, if there is a possibility to create own toolbar (panel) with
the icons of special symbols for quick insert they into document? I
want to have the possibility to add (and remove) on this toolbar
(panel) only those symbols which I need.
Thank you very much.

Hi avokin,

Good that you post this question in a VBA group... I think it's much easier
to create such a toolbar per macro than from the user interface.

Start the macro "Symbol_CreateToolbar" below to create the toolbar (or to
make it visible if it already exists).

Then, to add a symbol to the toolbar, select it in the text and click on the
"Add" button.

To remove symbols, you can simply drag them off the toolbar holding down the
ALT key.

In a short test, it seemed to work well with a wide variety of characters.
The tooltip (if you hover over a symbol button) shows you the font, and the
hex code.
If the button should not show the symbol, you'd have to edit its text by
hand (...say for spacing characters or other weird stuff).

Regards,
Klaus


Sub Symbol_CreateToolbar()
Dim myCBB As CommandBarButton
Dim strFont As String
Dim iSymbol As Long
Dim boolNew
boolNew = True
CommandBars.Add Name:="my Symbols"
CommandBars("my Symbols").Visible = True
For Each myCBB In CommandBars("my Symbols").Controls
If myCBB.Caption = "Add" Then
boolNew = False
End If
Next myCBB
If boolNew = True Then
Set myCBB = CommandBars("my Symbols").Controls.Add( _
Before:=1)
myCBB.Caption = "Add"
myCBB.TooltipText = "Click to add selected symbol to toolbar"
myCBB.Style = msoButtonCaption
myCBB.OnAction = "Symbol_Pickup"
End If
End Sub

Sub Symbol_PickUp()
Dim myCBB As CommandBarButton
Dim strFont As String
Dim iSymbol As Long
strFont = Selection.Font.Name
iSymbol = AscW(Selection.Text)
CommandBars.Add Name:="my Symbols"
CommandBars("my Symbols").Visible = True
Set myCBB = CommandBars("my Symbols").Controls.Add( _
Type:=msoControlButton, _
ID:=2290, _
Parameter:=ChrW(iSymbol) & strFont)
myCBB.Caption = ChrW(iSymbol)
myCBB.TooltipText = strFont & " " & Hex(iSymbol)
myCBB.Style = msoButtonCaption
End Sub
 
K

Klaus Linke

Oops... use the macros below, so you don't get more than one "my Symbols"
toolbar!

Sub Symbol_CreateToolbar()
Dim myCBB As CommandBarButton
Dim myCB As CommandBar
Dim strFont As String
Dim iSymbol As Long
Dim boolNew
CustomizationContext = NormalTemplate
boolNew = True
For Each myCB In CommandBars
If myCB.BuiltIn = False Then
If myCB.Name = "my Symbols" Then
boolNew = False
End If
End If
Next myCB
If boolNew = True Then
CommandBars.Add Name:="my Symbols"
End If
boolNew = True
CommandBars("my Symbols").Visible = True
For Each myCBB In CommandBars("my Symbols").Controls
If myCBB.Caption = "Add" Then
boolNew = False
End If
Next myCBB
If boolNew = True Then
Set myCBB = CommandBars("my Symbols").Controls.Add( _
Before:=1)
myCBB.Caption = "Add"
myCBB.TooltipText = "Click to add selected symbol to toolbar"
myCBB.Style = msoButtonCaption
myCBB.OnAction = "Symbol_Pickup"
End If
End Sub

Private Sub Symbol_PickUp()
Dim myCBB As CommandBarButton
Dim strFont As String
Dim iSymbol As Long
strFont = Selection.Font.Name
iSymbol = AscW(Selection.Text)
CommandBars.Add Name:="my Symbols"
CommandBars("my Symbols").Visible = True
Set myCBB = CommandBars("my Symbols").Controls.Add( _
Type:=msoControlButton, _
ID:=2290, _
Parameter:=ChrW(iSymbol) & strFont)
myCBB.Caption = ChrW(iSymbol)
myCBB.TooltipText = strFont & " " & Hex(iSymbol)
myCBB.Style = msoButtonCaption
End Sub
 
A

avkokin

Hello Klaus. Thank you very much! But if I'm adding symbol from font
Wingdings (for example code of symbol 129) then I'm getting other
symbol - "(". I think that is it depending from function "ASCW", but
how to do to add any symbols irrespective of language?
Big Thank you!
 
K

Klaus Linke

avkokin said:
Hello Klaus. Thank you very much! But if I'm adding symbol from font
Wingdings (for example code of symbol 129) then I'm getting other
symbol - "(". I think that is it depending from function "ASCW", but
how to do to add any symbols irrespective of language?
Big Thank you!

Sorry, I avoid symbol fonts like Wingdings, Zapf Dingbats, Symbol like the
plague.
They're notoriously hard to find for example, and tend to get messed up
during editing, or when you export or copy the text elsewhere.

Unicode is much nicer to work with...

With Unicode, you wouldn't really have to specify the font: A given code
always corresponds to the same character, unlike the symbol fonts. Only a
very few contain all Unicode characters, but say Arial or Times New Roman
have more than 1000 characters, including many symbols from common symbol
fonts.

The built-in toolbar button I use in the macro ("Symbol:" with Id 2290) does
force one to specify the font though (unfortunately... it dates back to
pre-Unicode times).

I don't know any way to get a character from a symbol font to display in a
button, so I see no way to make the macro work properly with them. You could
put the font name and the key on the button (similar to what's currently
visible in the tooltip), but that's not nearly as nice as seeing the
character, and takes up a lot of space.

Regards,
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top