Can anyone help toolbar struggle

  • Thread starter Thread starter Rivers
  • Start date Start date
R

Rivers

The code below is a toolbar that uses a menu option and then also a sub menu
but i cant figure out how to get the sub menu buttons to add to it can anyone
help


rivers

Sub newbar1()
Application.ScreenUpdating = False
On Error Resume Next

Application.CommandBars("saveas").Delete
With Application.CommandBars.Add
.Name = "Saveas"
.Visible = True
.Position = msoBarTop

' Help

Set cbp = CommandBars("saveas").Controls.Add(Type:=msoControlPopup,
Temporary:=False)
cbp.Caption = "Help.."

Set mysubmenu = cbp.Controls.Add(Type:=msoControlPopup)
With mysubmenu
..Caption = "Useful Websites"
End With

Set check = mysubmenu.Controls.Add(Type:=msoControlButton)
With check
Set cbb = check.Controls.Add
cbb.Caption = "Google"
cbb.OnAction = "google1"
cbb.Style = msoButtonIconAndCaption
cbb.FaceId = 9026 '218 + ictr
cbb.TooltipText = "Search engine"

End With
End With
End Sub
 
Good practice...
Use Option Explicit in all modules
Declare all variables
Be careful when using On Error Resume Next when developing code as
it hides problems.
'--
Sub newbar1()
Application.ScreenUpdating = False
Dim cbp As CommandBarControl
Dim mysubmenu As CommandBarControl
Dim check As CommandBarButton

On Error Resume Next
Application.CommandBars("saveas").Delete
On Error GoTo 0 '<<<

With Application.CommandBars.Add
.Name = "Saveas"
.Visible = True
.Position = msoBarTop
End With

Set cbp = CommandBars("saveas").Controls.AddType:=msoControlPopup, _
Temporary:=False)
cbp.Caption = "Help.. "

Set mysubmenu = cbp.Controls.Add(Type:=msoControlPopup)
mysubmenu.Caption = "Useful Websites"

Set check = mysubmenu.Controls.Add(Type:=msoControlButton)
With check
.Caption = "Google"
.OnAction = "google1"
.Style = msoButtonIconAndCaption
.FaceId = 1234 '9026 '218 + ictr
' .TooltipText = "Search engine"
End With
Application.ScreenUpdating = True
End Sub
--
Jim Cone
Portland, Oregon USA




"Rivers"
wrote in message
The code below is a toolbar that uses a menu option and then also a sub menu
but i cant figure out how to get the sub menu buttons to add to it can anyone
help
rivers

Sub newbar1()
Application.ScreenUpdating = False
On Error Resume Next

Application.CommandBars("saveas").Delete
With Application.CommandBars.Add
.Name = "Saveas"
.Visible = True
.Position = msoBarTop
' Help
Set cbp = CommandBars("saveas").Controls.Add(Type:=msoControlPopup,
Temporary:=False)
cbp.Caption = "Help.."
Set mysubmenu = cbp.Controls.Add(Type:=msoControlPopup)
With mysubmenu
..Caption = "Useful Websites"
End With
Set check = mysubmenu.Controls.Add(Type:=msoControlButton)
With check
Set cbb = check.Controls.Add
cbb.Caption = "Google"
cbb.OnAction = "google1"
cbb.Style = msoButtonIconAndCaption
cbb.FaceId = 9026 '218 + ictr
cbb.TooltipText = "Search engine"
End With
End With
End Sub
 
Hi Jim sorry or not putting the variables in the snippit of code forgot to
sorry.

jim how do i add more than one button i tried but cant

can you help?
 
Just repeat the "check" section as many times as necessary...
'--
Set check = mysubmenu.Controls.Add(Type:=msoControlButton)
With check
.Caption = "Foogle"
.OnAction = "Foogle2"
.Style = msoButtonIconAndCaption
.FaceId = 2345
End With
'--
Jim Cone
Portland, Oregon USA




"Rivers"
wrote in message
Hi Jim sorry or not putting the variables in the snippit of code forgot to
sorry.
jim how do i add more than one button i tried but cant
can you help?
 
Jim,

I'm wanting to do something similar for Excel 2007. Can you direct me to
some code for that or is it the same?

Thanks,
Barb Reinhardt

Jim Cone said:
Just repeat the "check" section as many times as necessary...
'--
Set check = mysubmenu.Controls.Add(Type:=msoControlButton)
With check
.Caption = "Foogle"
.OnAction = "Foogle2"
.Style = msoButtonIconAndCaption
.FaceId = 2345
End With
'--
Jim Cone
Portland, Oregon USA




"Rivers"
wrote in message
Hi Jim sorry or not putting the variables in the snippit of code forgot to
sorry.
jim how do i add more than one button i tried but cant
can you help?
 
Back
Top