In excel 2003 I wrote the following VB code that allowed a button to appear on the tool bar everytime someone opened a this workbook, and then when they closed it disappeared as well. However, it does not work on 2010 and I have no clue on how to make this appear onto the ribbon any ideas?
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim cb As CommandBar
For Each cb In Application.CommandBars
If cb.Name = "Menubaraa" Then
cb.Delete
End If
Next cb
End Sub
Private Sub Workbook_Open()
Dim count As Integer
Dim cb As CommandBar, f As Boolean, btn As CommandBarButton
f = False
For Each cb In Application.CommandBars
f = False Or (cb.Name = "Menubaraa")
Next cb
count = 1
If Not f Then
Set cb = Application.CommandBars.Add(Name:="Menubaraa", Position:=msoBarTop)
cb.RowIndex = msoBarRowLast
Set btn = cb.Controls.Add(Type:=msoControlButton)
With btn
.Caption = "&Enter Data"
.OnAction = "begin"
.FaceId = 151
.Style = msoButtonIconAndCaption
End With
cb.Visible = True
End If
Load UserForm1
UserForm1.Show
End Sub
Option Explicit
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim cb As CommandBar
For Each cb In Application.CommandBars
If cb.Name = "Menubaraa" Then
cb.Delete
End If
Next cb
End Sub
Private Sub Workbook_Open()
Dim count As Integer
Dim cb As CommandBar, f As Boolean, btn As CommandBarButton
f = False
For Each cb In Application.CommandBars
f = False Or (cb.Name = "Menubaraa")
Next cb
count = 1
If Not f Then
Set cb = Application.CommandBars.Add(Name:="Menubaraa", Position:=msoBarTop)
cb.RowIndex = msoBarRowLast
Set btn = cb.Controls.Add(Type:=msoControlButton)
With btn
.Caption = "&Enter Data"
.OnAction = "begin"
.FaceId = 151
.Style = msoButtonIconAndCaption
End With
cb.Visible = True
End If
Load UserForm1
UserForm1.Show
End Sub