In 2010 need a Marco button to appear on a ribbon by VB

JASONW10

Board Regular
Joined
Mar 11, 2005
Messages
231
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
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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

You might also need to check out your security level for the new version of Excel as MACRO's can be disabled which would prevent you from seeing the Add Ins Tab for this sub routine.
 
Upvote 0
yes, you are correct it does appear on the add in tab. is there away to have this tab auto show when you open a workbook?
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,812
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top