Microsoft Word Addin
Addin is referred a pre-compiled code kept in a separate file. Addin word describes an add-on feature that you would like to see in your existing Microsoft Word environment to commit certain tasks quickly.
Addin belongs to Addins collection which refers to a single Addin. The AddIns collection contains all the add-ins available to Microsoft Word. The Addins can be seen using Addin dialog box available at Developer ribbon.
Installed:
The Installed property commit this job for you. The addins are saved as .dot or .dotm format. Below example shows how to install a addin:
Public Sub InstallAddin() AddIns("myAddin.dot").Installed = True End Sub
Point to to be noticed marking Installed property “True” makes addin installed and “False” disables the addin. Also, instead of “myAddin.dot” we can use index (a positive integer) to reference an Addin from Addins collection as shown below where “1” is referring to “myAddin.dot“:
Public Sub InstallAddin() AddIns(1).Installed = True End Sub
The above code will Install “myAddin.dot” in Word.
Installing Adding referring to some external path. This can be achieved using Add method of Addins collection as shown below:
Public Sub InstallAddinWithfile() AddIns.Add FileName:="C:\myDirectory\myAddin.dot", Install:=True End Sub
Delete:
There might be some cases where you might want to discontinue your Addin as it may no longer be useful. Microsoft provides Delete method which help deleting/removing existing Addin from word:
Public Sub RemoveAddin() AddIns("C:\myDirectory\myAddin.dot").Delete End Sub
Addin Properties:
Microsoft Word object offers variety of properties which are useful for an Addin object. Let’s understand one by one:
Autoloaded:
This is a Read-only Boolean property. If the specified add-in is automatically loaded this property sets to True when Word is started. Add-ins located in the Startup folder in the Word program folder are automatically loaded.
Public Sub SearchAllAddin() Dim oAddin as AddIn Dim bFound as Boolean bFound = False For Each oAddin In AddIns With oAddin If .Autoload = True Then MsgBox .Name bFound = True End If End With Next oAddin If bFound <> True Then _ MsgBox "No add-ins were loaded automatically." End If End Sub
Complied:
It is a Read-only Boolean property. If the specified add-in is a Word add-in library (WLL) it is True. if the add-in is a template it is False. The given example checks if the first add-in is a template, this unloads the template and opens it:
Public Sub AddinFromFile() If Addins(1).Compiled = False Then Addins(1).Installed = False Documents.Open FileName:=AddIns(1).Path & Application.PathSeparator & AddIns(1).Name End If End Sub
Name:
This property returns name of the Addin. The given example will print all available Addins name in Immediate Window:
Public Sub GetAddinName() Dim oAddin As Addin For Each oAddin in Addins Debug.Print oAddin.Name Next oAddin End Sub
Parent:
This property returns the parent object of the Addin. Below example prints all available Addins’ parent name:
Public Sub GetAddinName() Dim oAddin As Addin For Each oAddin in Addins Debug.Print oAddin.Parant.Name Next oAddin End Sub
Path:
This is a read-only property and returns path of the referenced Addin. Given example will print all Addins’ path on Immediate Window:
Public Sub GetAddinPath() Dim oAddin As Addin For Each oAddin in Addins Debug.Print oAddin.Path Next oAddin End Sub