PDA

View Full Version : Solved: Add Command bar popup



Djblois
09-14-2006, 02:19 PM
I am trying to add a commandbar popup with this code and it just isn't working

Dim menuObject As CommandBarPopup
Dim menuItem As Object
Dim Tbar As CommandBar
Set Tbar = CommandBars.Add

With Tbar
.Name = "Business_Reporting_Today"
.Visible = True
.Position = msoBarTop
End With
Set menuObject = Tbar.Controls.Add(Type:=msoControlPopup, _
Before:=10, temporary:=True)
menuObject.Caption = "&Help"
Set menuItem = menuObject.Controls.Add(Type:=msoControlButton)
menuItem.OnAction = "About"
menuItem.Caption = "About"

it doesn't give me an error or anything it just doesn't work

Bob Phillips
09-14-2006, 02:30 PM
It cannot work, you just added a commandbar and then you try and place the control before the existing 10th control, by efault a new commandbar will have none.

Djblois
09-14-2006, 03:06 PM
That worked but only if I run the macro manually. Here is my full code:

Sub WorkBook_AddinInstall(ByVal Business_Reporting_Today As Workbook)
Dim Tbar, obj As CommandBar
Dim newDD As CommandBarControl
Dim newBtn As CommandBarButton
Dim menuObject As CommandBarPopup
Dim menuItem As Object
'delete old copy of toolbar
On Error Resume Next
Set obj = CommandBars("Business_Reporting_Today")
If Err.Number = o Then
With ThisWorkbook.Sheets("Settings")
.[I5].Value = obj.Top
.[I6].Value = obj.Left
End With
End If
obj.delete
'define toolbar
Set Tbar = CommandBars.Add
With Tbar
.Name = "Business_Reporting_Today"
.Visible = True
.Position = msoBarTop
End With
Set newBtn = Tbar.Controls.Add(Type:=msoControlButton)
With newBtn
.OnAction = "callblinco"
.Caption = "Blinco"
.Style = msoButtonCaption
End With
Set menuObject = Tbar.Controls.Add(Type:=msoControlPopup, _
temporary:=False)
menuObject.Caption = "Tools"
Set menuItem = menuObject.Controls.Add(Type:=msoControlButton)
menuItem.OnAction = "ConvertToProper"
menuItem.Caption = "Proper"
Set menuObject = Tbar.Controls.Add(Type:=msoControlPopup, _
temporary:=False)
menuObject.Caption = "Help"
Set menuItem = menuObject.Controls.Add(Type:=msoControlButton)
menuItem.OnAction = "About"
menuItem.Caption = "About"
End Sub

it will install the single button I named Blinco but not the others. How come????

Bob Phillips
09-14-2006, 03:39 PM
It seems to install them all here. I didn't run it as an addin, but in a normal macro.

Djblois
09-14-2006, 03:56 PM
I know, if I run it as a regular macro it installs them. However if I install the addin it doesn't

Bob Phillips
09-14-2006, 04:10 PM
The dedclaration of the addintall event is


Private Sub Workbook_AddinInstall()

End Sub


so yours is wrong.

Did you put it in the Thisworkbook code module?


Have you installed the addin (Tools>AddIns)?