I wasn't sure if this should be under the vba section or the com activeX section (or possibly classic VB) so if I've put it in the wrong place please acould a mod move it for me and accept my apologies

I'm writing an addin for word and need to put a button on the command bar. I cribbed the following code:-

Code:
Dim oWord As Object
Dim WithEvents cmdBrowseSLXContacts As Office.CommandBarButton

Private Sub AddinInstance_OnConnection(ByVal Application As Object, ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst As Object, custom() As Variant)
    Set oWord = Application
    Set cmdBrowseSLXContacts = oWord.CommandBars("Standard").Controls.Add(1)
    With cmdBrowseSLXContacts
        .Caption = "Browse SLX Contacts"
        .Style = msoButtonCaption
        .Tag = "Browse SLX Contacts"
        .OnAction = "!<" & AddInInst.ProgId & ">"
        .Visible = True
    End With
End Sub

Private Sub AddinInstance_OnDisconnection(ByVal RemoveMode As AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
    cmdBrowseSLXContacts.Delete
    Set cmdBrowseSLXContacts = Nothing
    Set oWord = Nothing
End Sub
from the microsoft help files.

The trouble is the example in the link was for an excel plugin and there appears to be a slight difference in the behaviour when I come to delete the button in the OnDisconnection event. It works fine in excel but when I try it in word I get a 'Run time error 424 : Object required' msgbox and the button doesn't delete (ie, the next time I open word there's 2 buttons, then 3, then 4, then I get frustrated and remove them all manually )

I think that the reference to cmdBrowseSLXContacts has been lost somewhere before the disconnect method is called (it exists when word is running because the events on it fire just fine) so when the cmdBrowseSLXContacts.delete call is made there's no cmdBrowseSLXContacts for it to act against. Can anyone help me with how to do this?