Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    Sep 2002
    Location
    Cleveland, Ohio
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find and Remove a Toolbar Button (VBA/Word 2003/SP2)

    I am looking for VBA code to search the Standard toolbar for a Save button and if it is found to delete it. I also need to search the File menu for the Save command and if it is found there, then delete it. Can anyone help?

    I tried using this code, that I use in Excel, but it deletes both the Save button and the Save As button. Am I on the right track?

    Sub RemoveItemFromToolbar(strTBName As String, _
    strButtonName As String)

    Dim cbarMenu As CommandBars
    Dim cctlControl As CommandBarControl

    ' Grab the application CommandBars object.
    Set cbarToolsMenu = Application.CommandBars

    ' DELETE: Toolbar button.
    ' Loop through the CommandBars.
    For Each cctlControl In cbarToolsMenu(strTBName).Controls
    With cctlControl
    ' Check to see if the toolbar is found.
    If .Caption = strButtonName Then

    ' If found, remove the command from the menu.
    .Delete

    End If

    End With
    Next cctlControl
    End Sub

    Then I call it like this:

    CommandBars("Standard").Reset
    RemoveItemFromToolbar "Standard", "Save"
    finalword

  2. #2
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Find and Remove a Toolbar Button (VBA/Word 2003/SP2)

    Unusual!

    On my machine (2003), using your code:
    call RemoveItemFromToolbar("Standard","Save &As...") Removes just the Save As button; while
    call RemoveItemFromToolbar("Standard","&Save") Removes just the Save button.
    Regards
    Don

  3. #3
    Star Lounger
    Join Date
    Sep 2002
    Location
    Cleveland, Ohio
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find and Remove a Toolbar Button (VBA/Word 2003/SP2)

    Tried that. It is still deleting both the Save As and Save buttons. Is there another properly that I could use?
    finalword

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Find and Remove a Toolbar Button (VBA/Word 2003/SP2)

    That's strange - there is no "Save As" button on the Standard toolbar, so how can it be deleted?

    Does this work better?
    <code>
    CommandBars("Standard").FindControl(ID:=3).Delete ' Save
    CommandBars("File").FindControl(ID:=3).Delete ' Save
    CommandBars("File").FindControl(ID:=748).Delete ' Save As
    </code>
    The IDs are language independent, as are the names of the top-level commandbars, so this should work in any version of Word.

  5. #5
    Star Lounger
    Join Date
    Sep 2002
    Location
    Cleveland, Ohio
    Posts
    92
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find and Remove a Toolbar Button (VBA/Word 2003/SP2)

    Hans...you are a life-saver this week! This code is much cleaner than that other stuff and works great!

    Thanks again for all your help!
    finalword

Posting Permissions

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