View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Charles Charles is offline
external usenet poster
 
Posts: 62
Default Adding an input box to a custom toolbar

I've actually been lucky:

http://www.ozgrid.com/forum/showthread.php?t=23224

it looks like this would work. tricky....

Public Const g_strCBRName As String = "MyCustomBar"

Sub CustomTB()

Dim cbrTemp As CommandBar
Dim objDrop As CommandBarControl

RemoveCustomTB

'Create commandbar
Set cbrTemp = Application.CommandBars.Add(g_strCBRName)

With cbrTemp
' Add control
Set objDrop = .Controls.Add(msoControlComboBox)
With objDrop
' add items
.AddItem "Andy"
.AddItem "Bob"
.AddItem "Charlie"
.OnAction = "cbrTest"
End With
' Add control textbox
Set objDrop = .Controls.Add(msoControlEdit)
With objDrop
.OnAction = "ctxTest"
End With
.Visible = True
End With

End Sub
Sub cbrTest()
MsgBox "You selected " &
Application.CommandBars(g_strCBRName).Controls(1). Text
End Sub
Sub ctxTest()
MsgBox "You entered " &
Application.CommandBars(g_strCBRName).Controls(2). Text
End Sub

Sub RemoveCustomTB()
' Try and delete commandbar
On Error Resume Next
Application.CommandBars(g_strCBRName).Delete
End Sub

Thanks
Charles