Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hiding a Menu Item (Word 2000 VBA)

    I created a macro to protect and unprotect a form section in a document. I created a menu item for each.

    I would like to hide the "Protect" item after the document is protected and unhide the "Unprotect" item. Visa-versa when an item is unprotected.

    It should be relatively easy but I am stumped. How do I hide and unhide a menu item?

    Thanks!!
    Troy

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Hiding a Menu Item (Word 2000 VBA)

    Try code like
    <code>Application.CommandBars("MyToolbar").Control s("Protect").Visible = False</code>

    StuartR

  3. #3
    4 Star Lounger
    Join Date
    Apr 2001
    Posts
    482
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding a Menu Item (Word 2000 VBA)

    I tried something similar to that. I even tried exactly what you mentioned. The following is the line of code based on what you mentioned:

    Application.CommandBars("Menu Bar").Controls("Tools").Controls("Unprotect Document").Visible = False

    I think I have the item name right. I have tried adding a wrong character so that it is mispelled and I get an invalid arguement error.

    As stated above, I get no errors. It just simply does not work.

    FORGET WHAT I WROTE ABOVE. I FOUND THE PROBLEM:

    I forgot to set the customization context. After I did that, everything worked fine.

    Thanks for the help!!
    Troy

  4. #4
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding a Menu Item (Word 2000 VBA)

    Instead of using 2 menu items, you can stick to 1 and toggle the caption of that item, very much like the standard menu item under Tools to (un)protect documents. You can do this by using the ActionControl property to determine which control triggered your Sub. Because I'm not on my own PC, I have to type this in from memory and cannot test it. But it should be someting like this (assuming that a click on the menu item fires this Sub):

    Public Sub SwitchProtection()
    Dim strCaption As String
    strCaption = Commandbars.ActionControl.Caption
    If strCaption = "Unprotect Document" Then
    'Your code to unprotect the document
    strCaption = "Protect Document"
    ElseIf strCaption = "Protect Document"
    'Your code to protect the document
    strCaption =

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Hiding a Menu Item (Word 2000 VBA)

    I use a similar idea on some of my menus. But I always use the TAG property, so that the caption can be translated without breaking my code. The problem with using this for toolbar items is that it is very hard to manipulate the graphic on a button from within code - and you often want a button to look different when you change its function.

    StuartR

  6. #6
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Hiding a Menu Item (Word 2000 VBA)

    You're quite right about the graphic, Stuart. That's exactly why I always use the Tag property too in case of commandbar buttons. But in this case we were talking about menu items with text, so I think it's save to use the Caption property.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •