create commandbar / control button using codes

G

Guest

dear frank/all,
i found the below from forum. its great and almost meet my needs.

1)first time, excel will create the toolbar and button but the next
time when i use the application, error comes out. how to ask excel not
to create as the toolbar and button already created?

2) how to change the smiley button to others using code? if all are
the same user will confuse.

3) how to name/put description to the button using code?

4) i put the following in a button. only authorised user allowed to
use the customised button created from the below. this will not affect
unauthorised personnel, rite? as i put this application in the server.

rgds



Sub create_toolbar()

Dim but1, but2, foundbut As Variant

Set foundbut = Application.CommandBars.FindControl _
(Type:=msoControlCustom, Tag:="Tender Toolbar")

If foundbut Is Nothing Then

Application.CommandBars.Add(Name:="Tender Toolbar").Visible = True

Set but1 = Application.CommandBars("Tender
Toolbar").Controls.Add(Type:=msoControlButton, ID:=2950, _
before:=1)

Set but2 = Application.CommandBars("Tender
Toolbar").Controls.Add(Type:=msoControlButton, ID:=2950, _
before:=2)

but1.OnAction = "Doing action"
but2.OnAction = "Doing action"

End If

End Sub
 
M

Myrna Larson

Did you look at John Walkenbach's code at www.j-walk.com ? It should answer
most of your questions.

As far as the 1st error is concerned, you should have code that removes the
toolbar and buttons when the workbook closes.
 
G

Guest

hi,
how to do remove? for those not using the toolbar/control button will
encounter error in this case. how to avoid?
thanks
 

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