I have this Add-In code below that works for me fine when I run it under macro's but how can I get this to run every time this excel file is open? this will be a shared file and most people don't even know how to get to macro's to run them let alone what they are. So I would like to have this Menu Command run when a user opens it so it will always be there. I have copied this from a place before and it works but I just can't get it to run automatically when the workbook opens.
Sub DeleteMenu()
On Error Resume Next
CommandBars(1).Controls("Add Employee or Product Code").Delete
End Sub
Sub CreateMenu()
Dim HelpMenu As CommandBarControl
Dim NewMenu As CommandBarPopup
Dim MenuItem As CommandBarControl
'delete the menu if it already exists
Call DeleteMenu
'find the Help Menu
Set HelpMenu = CommandBars(1).FindControl(ID:=30010)
If HelpMenu Is Nothing Then
'add menu to the end
Set NewMenu = CommandBars(1).Controls _
.Add(Type:=msoControlPopup, temporary:=True)
Else
'add the menu before help
Set NewMenu = CommandBars(1).Controls _
.Add(Type:=msoControlPopup, before:=HelpMenu.Index, _
temporary:=True)
End If
'Add Caption
NewMenu.Caption = "&Add Employee or Product Code"
'First Menu item
Set MenuItem = NewMenu.Controls.Add _
(Type:=msoControlButton)
With MenuItem
.Caption = "&Add New Product Code"
.FaceId = 162
.OnAction = "AddNewProductCode"
End With
'Second Menu item
Set MenuItem = NewMenu.Controls.Add _
(Type:=msoControlButton)
With MenuItem
.Caption = "Add Employee"
.FaceId = 162
.OnAction = "AddEmployee"
End With
'Third Menu item
Set MenuItem = NewMenu.Controls.Add _
(Type:=msoControlButton)
With MenuItem
.Caption = "Don't click me!"
.FaceId = 536
.OnAction = "checknames"
End With
End Sub
Function CommandBarExists(n)
Dim cb As CommandBar
For Each cb In CommandBars
If UCase(cb.name) = UCase(n) Then
CommandBarExists = True
Exit Function
End If
Next cb
CommandBarExists = False
End Function
Bookmarks