PDA

View Full Version : Solved: Simple problem with deleting toolbar buttons



samuelwright
12-08-2005, 03:09 AM
Hey all

Maybe its too early in the morning, but I have made a mistake in this code and I cant think:



Option Explicit
Sub Document_open()
Dim cb1 As CommandBarButton
For Each cb1 In Application.CommandBars("Standard").Controls

If cb1.Caption = "Subject Naming Utility" Then cb1.Delete

Next
End Sub



When I install a button in Outlook 2003, and I have Word 2003 as my editor, the button is still available in Word, although it is now non functional in Word. I simply want to delete it from my Word Toolbar...is the above wrong? I get a "Type Mismatch Error"

Sam :wot

samuelwright
12-08-2005, 04:12 AM
Never mind, it was too early in the morning, nothing a cup of strong coffee and engagement of brain couldn't sort out: the problem is fixed, heres what I did...


Sub Document_open()
Dim cb1 As Office.CommandBarControl
Dim cb2 As Office.CommandBar

On Error Resume Next
'Loop through all buttons to clear all "Subject Naming Utility" buttons
For Each cb1 In cb2.Controls
If cb1.Caption = "Subject Naming Utility" Then
cb1.Delete
End If
Next
'Clean up
Set cb2 = Nothing
End Sub