Can anyone help toolbar struggle

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
 
J

Jim Cone

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
 
R

Rivers

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?
 
J

Jim Cone

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?
 
B

Barb Reinhardt

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?
 

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