How to remove a button that my addin adds to the standard toolbar

S

sajin

Hi all ,

I have a button which i added to word addin ("Standard " toolbar) , i
want to delete this button from the "standard" toolbar
i am using vb .net 2005
My code is as follows
Dim oMissing As Object
oMissing = Type.Missing
Dim oCommandBars As Microsoft.Office.Core.CommandBars
Dim oStandardBar As Microsoft.Office.Core.CommandBar
Dim cmdBar As Microsoft.Office.Core.CommandBar
oCommandBars = aApp.CommandBars
oStandardBar = aApp.CommandBars.Add("My bar",
Core.MsoBarPosition.msoBarTop, oMissing, oMissing)
oStandardBar.Visible = True
If MyButton Is Nothing Then
MyButton = oStandardBar.Controls.Add(1)
With MyButton
.Caption = "Theme Manager"
.Style = Core.MsoButtonStyle.msoButtonCaption
.Tag = "Theme manager"
End With
End If

Regards
Sajin
 
T

Thaddaeus Parker

sajin:
instead of doing this:
oStandardBar = aApp.CommandBars.Add("My bar",
Core.MsoBarPosition.msoBarTop, oMissing, oMissing) try this:
oStandardBar = aApp.CommandBars.Add("My bar",
Core.MsoBarPosition.msoBarTop, oMissing, True)
by setting the Temporary parameter to true inside of your code you will see
that when the application is closed it will remove the item from the
standard bar. Otherwise, you will have the menu item always there even if
you really don't want it.

Now if you need to explicitly remove the item from the standard bar any time
during your execution of the addin you will have to do something similar to
this:
Dim cmdBar As Microsoft.Office.Core.CommandBar
oCommandBars = aApp.CommandBars
Dim menuItem as Microsoft.Office.Core.CommandBarControl
menuItem = aApp.CommandBars.Item("Standard").Controls.Item([Your
menu name])
If(menuItem IsNot NULL)
menuItem.Delete()

regards,

Thaddaeus.
 
S

sajin

Hi,
Thanks for ur reply

Basically i have an installer which instals the addin (adding button
into standard bar) , while uninstalling i want to remove this button
forever , meaning it should not be visible after the uninstallation

Thanks
Sajin
 
K

Ken Slovak - [MVP - Outlook]

That doesn't work for Word however, Word doesn't understand what temporary
means.




Thaddaeus Parker said:
sajin:
instead of doing this:
oStandardBar = aApp.CommandBars.Add("My bar",
Core.MsoBarPosition.msoBarTop, oMissing, oMissing) try this:
oStandardBar = aApp.CommandBars.Add("My bar",
Core.MsoBarPosition.msoBarTop, oMissing, True)
by setting the Temporary parameter to true inside of your code you will
see that when the application is closed it will remove the item from the
standard bar. Otherwise, you will have the menu item always there even if
you really don't want it.

Now if you need to explicitly remove the item from the standard bar any
time during your execution of the addin you will have to do something
similar to this:
Dim cmdBar As Microsoft.Office.Core.CommandBar
oCommandBars = aApp.CommandBars
Dim menuItem as Microsoft.Office.Core.CommandBarControl
menuItem =
aApp.CommandBars.Item("Standard").Controls.Item([Your menu name])
If(menuItem IsNot NULL)
menuItem.Delete()

regards,

Thaddaeus.
 
P

pavan

Yes, Word doesn't understand what temporary parameter means! The best
to resolve this issue is to make changes ie add buttons or menus or
whatever to a temporary template. Upon uninstall the template can be
removed and hance all changes can be reverted. Actually, when we add
any button the normal.dot file gets modified. And later even after
uninstallation since normal.dot file cant be modified the button doesnt
go away.

This method works and I've tried. Let me know if you need the code

Regards,
Pavan
 
K

Ken Slovak - [MVP - Outlook]

I use CustomizationContext to control where my buttons are added, then when
Word is closing (or a WordMail window) I find the buttons and delete them
and set up CustomizationContext.Saved so the user isn't prompted to save
unless they actually changed something themselves.
 
K

Ken Slovak - [MVP - Outlook]

Hi Cindy,

I almost always end up adding buttons to an existing toolbar since I'm
almost always working with Word as WordMail. So for me temporary doesn't
work. But you're correct of course, it would work for CommandBar objects.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top