Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help. Removing Menu Items only works sometimes.

Status
Not open for further replies.

Sorwen

Technical User
Nov 30, 2002
1,641
US
For various reasons I can use no other options on this project other than remove all instances of certain Menu Items from all Menus. I've seen a lot of other suggestions make MDE files, your own tool bars, etc. When I can finally remake this thing I will/would use those ideas. On this database I cannot do any of that. My only option is to remove the individual Menu Items.


The problems is some Menu Items seem to have unique rules that I cannot figure out. Like the "Tools" Item on the "Menu Bar" to remove "Startup...". I have to use another function that find looks at Tools like it is it's own Menu Bar and then removes it. If I try to use the below function it cannot find the Tools Bar. I have to directly state I'm looking for it so it will find it. That's fine as I know the only place it is going to show up is under Tools. My problem now is I have to remove the View option from all tool bars. If I call direct again it will remove fine with no problems, but if I use the below function it finds them, but then gives me a "Run-time error '5' Invalid Procedure Call or argument" error.

As you will see I use the Items ID. I've even ran into a problem where two items had the same ID? It says that built in menu items have their own ID so how can two of the have the same ID? That aside I don't know what I'm doing wrong. Can someone help me? What is it I'm just not seeing?


This is the function I'm using to remove all and will work fine for Menu Items like the "Code" buttons or "Macro" Menu Item (under Tools and other places).
Code:
Function RemoveAllMenuItem(ItemName As String, ItemId As Variant)
'Temporary removal of menu item
    
    Dim cmdMenu As Office.CommandBar
    Dim MenuItem As Office.CommandBarControl
    Dim MenuId As Office.CommandBarControl
        
    For Each cmdMenu In Application.CommandBars
    
        For Each MenuId In cmdMenu.Controls
            If MenuId.ID = ItemId Then
                Set MenuItem = cmdMenu.Controls(ItemName)
                MenuItem.Delete (True)
            End If
        Next MenuId
    Next cmdMenu

End Function


This is the function that removes a single and works fine.
Code:
Function RemoveMenuItem(MenuName As String, ItemName As String)
'Temporary removal of menu item

    Dim cmdMenu As Office.CommandBar
    Dim MenuItem As Office.CommandBarControl
    
    Set cmdMenu = Application.CommandBars(MenuName)
    
    Set MenuItem = cmdMenu.Controls(ItemName)
    
    MenuItem.Delete (True)

End Function
 
How are ya Sorwen . . .

[ol][li]Certainly your not using all menu's and since you can show only those of interest, whats the point in removing a specific item from them all![/li]
[li]Have you tried removing them in customize (Tools - Customize)?[/li][/ol]

Calvin.gif
See Ya! . . . . . .
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top