Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

option button in toolbar 2

Status
Not open for further replies.

peljo

Technical User
Mar 3, 2006
91
BG
Can somebody help me build an option button in a toolbar ? I mean a button with dropped down 2 possibilities needed to build a code.I can build a single button with the code shown below.i will be grateful if someone could help me built an option button with the same code.

Sub ToolbarCustomers()

Dim cbr As Object
Dim cbb As Object
' msoBarTop = 1
Set cbr = CommandBars.Add(Name:="MyToolbarCustomers", Position:=1, Temporary:=True)


1. msoControlButton = 1 First buton MyBack2
Set cbb = cbr.Controls.Add(Type:=1, Temporary:=True)
With cbb
'.Caption = "My Button"
' msoButtonCaption = 2
' .Style = 2
.FaceId = 41
.Width = 60
.FontWeight = 800


.OnAction = "MyBack2"
End With
 
The example below builds a toolbar with three option buttons. Obviously, change the FaceID's and OnAction macros.

Private Sub Command0_Click()
With Application.CommandBars.Add("MyToolbar", , False, True)
.Visible = True
.Position = msoBarLeft
With .Controls
With .Add(msoControlButton)
.Caption = "Button1"
.FaceId = 12
.OnAction = "listboxtest"
End With
With .Add(msoControlButton)
.Caption = "Button2"
.FaceId = 12
.OnAction = "listboxtest"
End With
With .Add(msoControlButton)
.Caption = "Button3"
.FaceId = 12
.OnAction = "listboxtest"
End With
End With
End With
End Sub
 
You can put a drop-down combo with the code:
Code:
Sub CreateToolbar()
With Application.CommandBars.Add("MyToolbar", , False, True)
    .Visible = True
    .Position = msoBarTop
    With .Controls
        With .Add(msoControlDropdown)
            .AddItem "Option 1"
            .AddItem "Option 2"
            .Style = msoComboNormal
            .ListIndex = 2
            .OnAction = "RespondCombo"
        End With
    End With
End With
End Sub

Sub RespondCombo()
MsgBox Application.CommandBars("MyToolbar").Controls(1).ListIndex
End Sub

combo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top