M
Minitman
Greetings,
I need to add a command button to the menu bar.
How is that done?
-Minitman
I need to add a command button to the menu bar.
How is that done?
-Minitman
Minitman said:Hey Julie,
Just a quick questions, how do I remove it?
-Minitman
Manual or with code?
I would like to know how to do it with code. My attempts always showed a
blank button underneath it when clicked.
Here is a example to add and delete a item on the menu bar
Sub MenuBar_Item()
On Error Resume Next
Application.CommandBars(1).Controls("Hi").Delete
On Error GoTo 0
With Application.CommandBars(1)
.Controls.Add(Type:=msoControlPopup, before:=1).Caption = "&Hi"
.Controls("Hi").OnAction = ThisWorkbook.Name & "!TestMacro"
End With
End Sub
Sub MenuBar_Item_Delete()
On Error Resume Next
Application.CommandBars(1).Controls("Hi").Delete
On Error GoTo 0
End Sub
Sub TestMacro()
MsgBox "Hi"
End Sub
I put this under the ThisWorkbook module:
Option Explicit
Private Sub Workbook_Activate()
Call MenuBar_Item
End Sub
Private Sub Workbook_Deactivate()
Call MenuBar_Item_Delete
End Sub
And all of Ron's code in a General module and it worked nicely for me.
(I'm betting you didn't put the TestMacro in a General Module.)
======
When I tried your code, the control matched nicely (xl2002). I don't
have a suggestion for you.
Good change Dave
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.