Insert Character - Built-In Excel Commands

T

Tonto

In Excel 2003, a toolbar can be customized using
Tools|Customize|Commands and dragging certain buttons to the toolbar.
Some of these buttons can be used to insert special characters while
typing, such as these:

= + - * / ^ ( ) : , % $

There is also a button with the Greek letter omega on it for calling
up the insert symbol dialog box.

I would like to create a toolbar consisting of buttons that insert
special characters on the fly like these buttons. I would like to
have a button for, among other things, each of the Greek letters from
the unicode set used by the Excel insert symbol dialog box. I don't
want to use the Symbol font, but rather the Times New Roman font with
its unicode Greek letters, which is what the Excel insert symbol
dialog box uses. Rather than having to invoke the insert symbol
dialog, scroll down to the Greek Letters, and select the one I want, I
want to just click on a toolbar button for that letter.

I assume there is a command that the built-in Excel buttons invokes
for the button for each of the characters

= + - * / ^ ( ) : , % $

I assume that I can invoke the same command, and just replace the
character. However, I can't figure out what those commands are.

Does anybody have any idea how to accomplish my goal? What commands
are invoked by the buttons listed above? Is there a comprehensive
list of Excel commands such as the list of Word commands here:

http://word.mvps.org/FAQs/General/CommandsList.htm
 
K

keepITcool

Tonto..

nice one to play with :)

if your (windows defined) font used for the toolbars doesnt support
unicode you may have a problem, else this seems to work :)

the onaction string is hardcoded for Module1..
(so all procs can be in an addin and Private)
adapt to needs...



Sub BuildGreek()
Dim i%
Const uc = &H390
On Error Resume Next
With Application
..CommandBars("greek").Delete
On Error GoTo 0
With .CommandBars.Add("greek", msoBarTop, , True)

For i = 1 To 25
If i <> 18 Then
With .Controls.Add(msoControlButton, , ChrW(i + uc), , True)
.Style = msoButtonCaption
.OnAction = ThisWorkbook.Name & "!module1.DoGreek"
.Caption = ChrW(i + uc)
End With
End If
Next
..Visible = True
End With
End With

End Sub

Sub DoGreek()
ActiveCell.Value = Application.CommandBars.ActionControl.Parameter
ActiveCell.Font.Name = "Courier New"
End Sub


keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 
T

Tonto

Thanks. I changed it slightly like below to more efficiently account
for the small Greek letters, which I added. I also changed to module
reference to basGreek instead of Module1, so that I can put it in its
owm module in the Personal Macro Workbook.

This is a great start. However, what the DoGreek sub does is to
change the value of the active cell to the selected Greek letter.
What I want to do is to emulate the functionality of the
= + - * / ^ ( ) : , % $
optional buttons which a user can place on a toolbar using
Tools|Customize|Commands. These buttons, clicked when actively
editing a cell, will insert the appropriate character into the cell at
the point of the cursor. I am hoping somebody can tell me what
commands these buttons invoke so that I can apply a modified version
to your code. It is excellent, thank you.


Sub BuildGreek()

Dim i%

Const uc = &H390

With Application
On Error Resume Next
.CommandBars("Greek").Delete
On Error GoTo 0
With .CommandBars.Add("Greek", msoBarTop, , True)
For i = 1 To 57
Select Case i
Case 18, 26 To 32
'Do nothing.
Case Else
With .Controls.Add(msoControlButton, , ChrW(i
+ uc), , True)
.Style = msoButtonCaption
.OnAction = ThisWorkbook.Name &
"!basGreek.DoGreek"
.Caption = ChrW(i + uc)
End With
End Select
Next
.Visible = True
End With
End With

End Sub

Sub DoGreek()

ActiveCell.Value = Application.CommandBars.ActionControl.Parameter
ActiveCell.Font.Name = "Courier New"

End Sub
 

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