-
Solved: Add Command bar popup
I am trying to add a commandbar popup with this code and it just isn't working
[VBA]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"[/VBA]
it doesn't give me an error or anything it just doesn't work
-
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.
-
That worked but only if I run the macro manually. Here is my full code:
[VBA]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[/VBA]
it will install the single button I named Blinco but not the others. How come????
-
It seems to install them all here. I didn't run it as an addin, but in a normal macro.
-
I know, if I run it as a regular macro it installs them. However if I install the addin it doesn't
-
The dedclaration of the addintall event is
[vba]
Private Sub Workbook_AddinInstall()
End Sub
[/vba]
so yours is wrong.
Did you put it in the Thisworkbook code module?
Have you installed the addin (Tools>AddIns)?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules