Word (2007) Add-In

A

Alan

I created a VBA macro and turned it into a Word (2007) Add-In saved
in a template. Every time I open the document, it adds another copy
of the same macro to the Add-In command menu. The code I am using to
automatically start and exit the add-in is shown below.

Should I be doing something differently to avoid this
problem?

Thanks, Alan

Public Sub AutoExec()
Dim objcommandbutton As CommandBarButton
Set objcommandbutton = Application.CommandBars
("Tools").Controls.Add _
(Type:=msoControlButton,
Before:=1)
objcommandbutton.Caption = "Get Selected Text"
objcommandbutton.OnAction = "GetSelectedText"
End Sub

Public Sub AutoExit()
Dim objcommandbutton As CommandBarControl
For Each objcommandbutton In Application.CommandBars
("Tools").Controls
If objcommandbutton.Caption = "Get Selected Text" Then
objcommandbutton.Delete
End If
Next objcommandbutton
End Sub
 
B

billbell52

I had this problem before. Lookup CustomizationContext Property. You
need to add it to the right template. I add it to my template not
normal.dot. I ended up deleting the menu prior to adding it again.
This way I always get the latest one when loading the template.

Dim cBar As CommandBarControl

Set cBar = Application.CommandBars("Menu Bar").FindControl
(Type:=msoControlPopup, Tag:="MyMenu")
If Not cBar Is Nothing Then
cBar.Delete
End If
 

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