Drop Down List in Toolbar 
Author Message
 Drop Down List in Toolbar

Hi Pierre,

Here's the example provided by the help file:

CommandBarComboBox Change Event Example

The following example creates a command bar with a CommandBarComboBox
control containing four selections. The combo box responds to user
interaction through the CommandBarComboBox_Change event.

Private ctlComboBoxHandler As New ComboBoxHandler
Sub AddComboBox()

    Set HostApp = Application

    Dim newBar As Office.CommandBar
    Set newBar = HostApp.CommandBars.Add(Name:="Test CommandBar",
Temporary:=True)
    Dim newCombo As Office.CommandBarComboBox
    Set newCombo = newBar.Controls.Add(msoControlComboBox)
    With newCombo
        .AddItem "First Class", 1
        .AddItem "Business Class", 2
        .AddItem "Coach Class", 3
        .AddItem "Standby", 4
        .DropDownLines = 5
        .DropDownWidth = 75
        .ListHeaderCount = 0
    End With
    ctlComboBoxHandler.SyncBox newCombo
    newBar.Visible = True

End Sub
The preceding example relies on the following code, which is stored in a
class module in the VBA project.

Private WithEvents ComboBoxEvent As Office.CommandBarComboBox

Public Sub SyncBox(box As Office.CommandBarComboBox)
    Set ComboBoxEvent = box
    If Not box Is Nothing Then
        MsgBox "Synced " & box.Caption & " ComboBox events."
    End If

End Sub

Private Sub Class_Terminate()
    Set ComboBoxEvent = Nothing
End Sub

Private Sub ComboBoxEvent_Change(ByVal Ctrl As Office.CommandBarComboBox)
    Dim stComboText As String

    stComboText = Ctrl.Text

        Select Case stComboText
        Case "First Class"
            FirstClass
        Case "Business Class"
            BusinessClass
        Case "Coach Class"
            CoachClass
        Case "Standby"
            Standby
    End Select

End Sub
Private Sub FirstClass()
    MsgBox "You selected First Class reservations"
End Sub
Private Sub BusinessClass()
    MsgBox "You selected Business Class reservations"
End Sub
Private Sub CoachClass()
    MsgBox "You selected Coach Class reservations"
End Sub
Private Sub Standby()
    MsgBox "You chose to fly standby"
End Sub

--
Bill Coan
Microsoft Word MVP
Neenah WI 54956 USA
http://www.*-*-*.com/
. . .

Quote:
> Hi,

> Using Word2000.

> We have several buttons in the toolbar to activate a specific printer.
> A macro attached to the button does the work.

> Because there are already many printers, I would like to create a drop
down
> list, similar to the font type or font size drop list.
> Each item would be a specific printer.
> When you click on an item, then a macro is activated that chooses the
> printer.

> I don't know how to proceed.
> Could somebody help please?

> Thanks
> Pierre Deblaere



Wed, 31 Jul 2002 03:00:00 GMT  
 Drop Down List in Toolbar
Hi,

Using Word2000.

We have several buttons in the toolbar to activate a specific printer.
A macro attached to the button does the work.

Because there are already many printers, I would like to create a drop down
list, similar to the font type or font size drop list.
Each item would be a specific printer.
When you click on an item, then a macro is activated that chooses the
printer.

I don't know how to proceed.
Could somebody help please?

Thanks
Pierre Deblaere



Thu, 01 Aug 2002 03:00:00 GMT  
 Drop Down List in Toolbar
Hi Pierre,

Quote:
> Because there are already many printers, I would like to create a drop down
> list, similar to the font type or font size drop list.
> Each item would be a specific printer.
> When you click on an item, then a macro is activated that chooses the
> printer.

Romke Soldaat has written an article in the December issue of "Microsoft
Office and VBA Developer" from Informant publications that is about doing
exactly this. I think you can find it at
    http://www.officevba.com/features/1999/12/vba199912hk_f/vba199912hk_f...

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



Thu, 01 Aug 2002 03:00:00 GMT  
 Drop Down List in Toolbar
Hi Bill & Cindy,

Thanks to both of you for the suggestions.

I finally implemented the solution of Romke Soldaat.

I think there's a small error in the programming.
In Word, if no document window is open, and you choose the Open button, and
then Open, Word will crash.
You even have to reboot the computer then.
So I wiped out everything concerning Open, Save and New and kept the stuff
about Print.
And that is exactly what I was looking for.

Again many thanks for your help.

Regards
Pierre



Sat, 03 Aug 2002 03:00:00 GMT  
 Drop Down List in Toolbar
Hi Pierre,

Quote:
> I think there's a small error in the programming.
> In Word, if no document window is open, and you choose the Open button, and
> then Open, Word will crash.

Thanks for reporting this; I'll make a note in my copy of the issue. Rather
surprising, really, since there's an "On Error Resume Next" at the beginning
of that procedure. When you say "crash", do you mean Word locks up and you
have to "End Task"? If it's something else, could you detail the behavior,
please?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister
http://go.compuserve.com/MSOfficeForum

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)



Sun, 04 Aug 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Drop Down List Box - Drop Down portion does not always disappear after Click event

2. Creating Drop down lists (non combo boxes) in VB5 Toolbar

3. Drop-down list in a list view

4. List of servers in VB for a drop down list

5. Press F1 key while drop-down menu item highlighted, drop-down menu stays on top

6. VBA code to go to a bookmarked drop down goes to wrong drop down

7. Drop down on Toolbar control

8. drop-down toolbar button

9. Drop down box on toolbar

10. Toolbar and drop down buttons in VB 6.0

11. Drop-Down Toolbar buttons

 

 
Powered by phpBB® Forum Software