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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Find and Remove a Toolbar Button (VBA/Word 2003/SP2)

    Author
    Topic
    #452316

    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”

    Viewing 0 reply threads
    Author
    Replies
    • #1116439

      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.

      • #1116456

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

        • #1116457

          That’s strange – there is no “Save As” button on the Standard toolbar, so how can it be deleted?

          Does this work better?

          CommandBars("Standard").FindControl(ID:=3).Delete ' Save
          CommandBars("File").FindControl(ID:=3).Delete ' Save
          CommandBars("File").FindControl(ID:=748).Delete ' Save As

          The IDs are language independent, as are the names of the top-level commandbars, so this should work in any version of Word.

          • #1116463

            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!

    Viewing 0 reply threads
    Reply To: Find and Remove a Toolbar Button (VBA/Word 2003/SP2)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: