Custom toolbar with a pull down combo box

S

Shane

Is it possible to create a custom toolbar with a combo box in Word? I have a short cut key that runs a macro which does one of a number of things. I would like the user to be able to select an option from a combo box on the menu bar that my macro can then use to determine its action. In other words the combo box will provide a variable input for my macro.

If this is possible, my next question is how do I write to or reference this combo box from within my macro

Thank you for your tim

Shan
 
J

Jezebel

Check Help on the CommandBarCombobox object.



Shane said:
Is it possible to create a custom toolbar with a combo box in Word? I have
a short cut key that runs a macro which does one of a number of things. I
would like the user to be able to select an option from a combo box on the
menu bar that my macro can then use to determine its action. In other words
the combo box will provide a variable input for my macro.
If this is possible, my next question is how do I write to or reference
this combo box from within my macro?
 
J

Joost Verdaasdonk

Hi Shane, :D

Hope you have some basic VBA skills?

Insert a Module and copy this code:
Code:
Option Explicit

Sub StartBar()
Dim cmdB As CommandBar

On Error Resume Next
Call KillBar
On Error GoTo 0

Set cmdB = ActiveDocument.CommandBars.Add("Custom",
msoBarTop, , True)

With cmdB
.Visible = True

With .Controls.Add(msoControlComboBox)
.AddItem "Hai"
.AddItem "Hello"
.Caption = "CustomCombo"
.OnAction = "ShowMessage"
End With
End With

Set cmdB = Nothing

End Sub

Sub ShowMessage()

Select Case ActiveDocument.CommandBars("Custom").Controls
(1).ListIndex

Case 1
MsgBox "You've pressed: Hai"
Case 2
MsgBox "You've pressed: Hello"
Case Else
MsgBox "How could this happen?"
End Select

End Sub

Sub KillBar()
ActiveDocument.CommandBars("Custom").Delete
End Sub

Next copy this code in the Class "ThisDocument":
Code:
Option Explicit

Private Sub Document_Open()
Call StartBar
End Sub

Private Sub Document_Close()
On Error Resume Next
Call KillBar
End Sub

Save and close you're document and restart it.
A new cmdbar will show up and a macro is fired on
selection.

There are numerous things you can do with this control
but lets start at the basics!

Enjoy,
Joost Verdaasdonk
 

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