PDA

View Full Version : How to remove (Delete) a Word global template add-in from the Add-ins list?



DaVinney
01-24-2013, 07:45 PM
How can I programmatically delete a single add-in? I don't want to deactivate it (uncheck it), I want to delete it completely. I know the specific name, say "MyTemplate.dotm".

I found the following code posted that supposedly deletes all deactivated add-ins, but what would be the syntax for a specific template?


Private Sub Delete_UnInstalled_WordAddins()
Dim oAddin As AddIn
On Error GoTo Err_Addin
For Each oAddin In AddIns
If oAddin.Installed = False Then
oAddin.Delete
End If
Next oAddin
Finally:
If Not oAddin Is Nothing Then Set oAddin = Nothing
Err_Addin:
If Err < > 0 Then
Err.Clear
GoTo Finally
End If
End Sub

gmaxey
01-24-2013, 08:30 PM
You need to know the path:
AddIns( _
"FullPath\MyTemplate.dotm" _
).Delete

DaVinney
01-24-2013, 08:44 PM
Thanks for the reply, Greg. :hi:

Will that actually delete the .dotm file itself, or just remove the add-in from the Add-ins list in Word? I only want the latter result.

fumei
01-24-2013, 08:57 PM
It just removes it from the Addins collection.

DaVinney
01-24-2013, 09:10 PM
I tried the syntax Greg posted and it moved the add-in from the 'Active Application Add-ins' list to the 'Inactive' list. That's better, but any way to make it vanish from the lists altogether? BTW, it also appears in the 'Global templates and add-ins' list preceded by an unchecked checkbox. I would like for it not to appear in this list at all.

Thanks for the info.

fumei
01-24-2013, 09:14 PM
You do not actually need to know the path. You can pick that up programmatically.

Sub RemoveUnusedAddin()
Dim oAddin As AddIn
For Each oAddin In AddIns
If oAddin.Installed = False Then
AddIns(oAddin.Path & "\" & oAddin.Name).Delete
End If
Next
End Sub

fumei
01-24-2013, 09:23 PM
The above completely removes all inactive addins from the list. Or at least it does for me.

gmaxey
01-24-2013, 09:59 PM
Well, I only tested with one that "appears in the 'Global templates and add-ins' list preceded by an unchecked checkbox" and it deleted it from that list. Maybe you have to run the code twice?

fumei
01-24-2013, 11:40 PM
I tested with six addins on the list.

Three checked.
Three unchecked.

The code (executed only once) completely removed the unchecked addins from the list.

DaVinney
01-25-2013, 04:41 PM
This info has helped a lot. Still getting some mixed results, though. To explain further:
I've been using autoexec in a template (Template1.dotm) in local \startup folder to load 2 other global templates (Template2.dotm/Template3.dotm) that are located on a remote server. Since Template1 is only used to load the other 2 add-ins, I wish to remove it from the add-in list after it serves its purpose. I don't want it to cause confusion, etc.

First, to "uncheck" it in the add-ins list I used:

AddIns("Template1.dotm").Installed = False[/vba]
Then, I used fumei's code to remove it from the add-ins list:
[vba] Dim oAddin As AddIn
For Each oAddin In AddIns
If oAddin.Installed = False Then
AddIns(oAddin.Path & "\" & oAddin.Name).Delete
End If
Next

The steps above moved the add-in from the 'Active Application Add-ins' list to the 'Inactive' list. It still appears in the 'Global templates and add-ins' list preceded by an unchecked checkbox.

I tried running code twice, no difference. Ideally, I'd like the add-in to vanish from all lists. :think:

fumei
01-25-2013, 05:33 PM
Ah, you did not mention they were in Startup. I never put global addins in Startup.

No, sorry, because Startup loads them (i.e. puts them in the list) when Word starts up (duh), they remain on the list for that session of Word. And since if you stop that session and start Word up again you load them again, you are stuck. They are on the list. You can uncheck them, but not remove them. The Remove button is greyed out, yes?

It is for this reason that we had a VERY small global addin in staff Startup that did ONE thing...dynamically load/unload the real addins from a network folder (i.e. NOT Startup).

I do not think there is a way around this for you. They are loaded from Startup and persist for that session of Word.

This is why I do not put addins in Startup. They remain.

DaVinney
01-25-2013, 08:04 PM
Okay, that explains it then. It's not the end of the world, but I was hoping for a cleaner load up.

Thanks very much for the nifty code. :hi:

fumei
01-26-2013, 12:23 AM
May I ask why this was important? You were concerned users could activate the addins? What would be the negative of that?

If there IS a serious negative, then I suggest you consider having them loaded dynamically, rather than through Startup. From a systems perspective it is better:

1. the basic wee addin IN Startup only does one thing, and so there is little (or none) maintenance required;
2. the working addins can be left on a network drive(not the users) which makes them more secure as they can be used by users, but the files themselves can be denied access;
3. the working addins, by remaining on the network, are not affected by any altered circumstances on any individual machine, thus making maintenance, testing and error correction of the addins greatly simplified.

DaVinney
01-26-2013, 01:03 PM
My desire to have the add-in removed from the add-ins list is nothing too important or critical, just I think it will be cleaner, that's all. For instance, if a user goes to the list and sees the unchecked add-in (that's actually not doing anything after it serves its purpose), it may result in a help desk call or something. Just cleaner to have it removed from the list, out of sight, out of mind, you know.

As I mentioned in a post above, the add-in in the startup folder is a very small .dotm that has no other purpose than to load 2 other global add-ins from a secure location on a remote network server. This method is set up essentially as you describe above. The add-ins on the server are more easily updated/maintained that way.

Not sure what you mean by "loaded dynamically". Definitely interested, though.

fumei
01-26-2013, 02:37 PM
"the add-in in the startup folder is a very small .dotm that has no other purpose than to load 2 other global add-ins from a secure location on a remote network server. This method is set up essentially as you describe above. The add-ins on the server are more easily updated/maintained that way."

That is precisely why. So does the wee one load the others automatically? It seems so.

By dynamically, I mean that ours added a toolbar icon which had:

Finance
Personnel
Engineering

and others.

That way, the Finance people got the Finance addins, Personnel got the theirs, Engineering got theirs.

It was a toggle. Click again, it was removed.

Tom.Stein
10-15-2021, 06:12 AM
Okay, propably too late for you, but this helped me and might help others:


The steps above moved the add-in from the 'Active Application Add-ins' list to the 'Inactive' list. It still appears in the 'Global templates and add-ins' list preceded by an unchecked checkbox.

I tried running code twice, no difference. Ideally, I'd like the add-in to vanish from all lists. :think:

You can ".Installed=False" the AddIn, you can ".Delete" the AddIn (as you mentioned) and - tadaaa! - you can delete the file using "Kill(oAddin.Name)". That will physically remove it for the entire outside world. BUT you will still see it in the AddIns-list until you close Word, and you can not use FileCopy or anything to recreate it, as Word thinks this AddIn is still there until you close Word.