Hi.
I have added code to add 2 command bar controls which in turn have sub
controls running seperate macros. The problem is that the command bar contols do not appear on workbook open, which they should do, and have done in the past? Please any suggestions! Thanks.
Option Explicit
Private Sub Workbook_Open()
Dim cmbBar As CommandBar
Dim cmbControl As CommandBarControl
Set cmbBar = Application.CommandBars("Worksheet Menu Bar")
Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup, temporary:=True)
With cmbControl
.Caption = "&Clear Contents"
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Clear Fault Codes"
.OnAction = "Clear"
.FaceId = 71
End With
Set cmbBar = Application.CommandBars("Worksheet Menu Bar")
Set cmbControl = cmbBar.Controls.Add(Type:=msoControlPopup, temporary:=True)
With cmbControl
.Caption = "&Import Codes"
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Import codes1"
.OnAction = "collect1"
.FaceId = 71
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Import codes2"
.OnAction = "collect2"
.FaceId = 72
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Import codes3"
.OnAction = "collect3"
.FaceId = 73
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Import codes4"
.OnAction = "collect4"
.FaceId = 74
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Import codes5"
.OnAction = "collect5"
.FaceId = 75
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Import codes6"
.OnAction = "collect6"
.FaceId = 76
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Import codes7"
.OnAction = "collect7"
.FaceId = 77
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Import codes8"
.OnAction = "collect8"
.FaceId = 78
End With
With .Controls.Add(Type:=msoControlButton)
.Caption = "&Import codes9"
.OnAction = "collect9"
.FaceId = 79
End With
End With
End With
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("Clear contents").Delete
On Error Resume Next
Application.CommandBars("Worksheet Menu Bar").Controls("Import Codes").Delete
End Sub
Bookmarks