multiple buttons on toolbar

S

sydney

Hello
I am using Microsoft Office XP Developer to develop a vba com add-in for
word xp.
Using wizards I have got as far as making my toolbar work (woohoo).
My toolbar will contain atleast ten buttons and I need to know if I am doing
this the long way.
Below is the code to set the toolbar and add two buttons, do I need to dim
every commandbarbutton I need to create or is there a shorter way?
Thanks a bunch.


' Specify the command bar
Dim cbcmybar As Office.CommandBar
Dim btnMyButton As Office.CommandBarButton ' first button
Dim btnPrecTbar As Office.CommandBarButton 'second button. check if need
to cont. this pattern for every button.


Set cbcmybar = CommandBars.Add(Name:="My new toolbar")

' Specify the commandbar button
Set btnMyButton = cbcmybar.Controls.Add(Type:=msoControlButton, _
Parameter:="1")
With btnMyButton
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "First butn"
.TooltipText = "this is a test"
End With

'Add another menu to the toolbar
Set btnPrecTbar = cbcmybar.Controls.Add(Type:=msoControlButton, _
Parameter:="2")
With btnPrecTbar
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "second butn"
.TooltipText = "my second button"
End With
 
M

Milo¹ Vukov

Hi,

No you don't need to dim evry button.It's like this:

Dim btnMyButton As Office.CommandBarButton 'button

'Add first butn
Set btnMyButton = cbcmybar.Controls.Add(Type:=msoControlButton, _
Parameter:="1")
With btnMyButton
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "First butn"
.TooltipText = "this is a test"
End With
'Add second butn
Set btnMyButton = cbcmybar.Controls.Add(Type:=msoControlButton, _
Parameter:="2")
With btnMyButton
.Style = msoButtonCaption
.BeginGroup = False
.Caption = "Second butn"
.TooltipText = "this is a test 2"
End With


***********************************************************
 
S

sydney

Thanks heaps :)

Milo¹ Vukov said:
Hi,

No you don't need to dim evry button.It's like this:

Dim btnMyButton As Office.CommandBarButton 'button

'Add first butn
Set btnMyButton = cbcmybar.Controls.Add(Type:=msoControlButton, _
Parameter:="1")
With btnMyButton
.Style = msoButtonCaption
.BeginGroup = True
.Caption = "First butn"
.TooltipText = "this is a test"
End With
'Add second butn
Set btnMyButton = cbcmybar.Controls.Add(Type:=msoControlButton, _
Parameter:="2")
With btnMyButton
.Style = msoButtonCaption
.BeginGroup = False
.Caption = "Second butn"
.TooltipText = "this is a test 2"
End With


***********************************************************
 
H

Helmut Obertanner

Hello,
why not write a function to create a button the you can type:

AddButton(style as ..., caption as String, beginGroup as Boolean
AddButton(style as ..., caption as String, beginGroup as Boolean
AddButton(style as ..., caption as String, beginGroup as Boolean

--
regards

Helmut Obertanner
Technical Consultant

Softwaredevelopment
DATALOG Software AG | Zschokkestr. 36 | D-80687 Munich
web: www.datalog.de


.... and IT works!
 
S

sydney

This looks good but its too advanced for me. Never the less, I will give it
a shot.

Thanks heaps.
 

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