Adding An Item To The Addins Collection

The add-in files that make up the AddIns collection can be stored anywhere. Excel maintains a partial list of these files and their locations in the Windows Registry. For Excel 2003, this list is stored at

HKEY_CURRENT_USER\Software\Microsoft\Ɯffice\11.0\Excel\Add-in Manager

You can use the Windows Registry Editor (regedit.exe) to view this Registry key. Note that the standard add-ins that are shipped with Excel do not appear in this Registry key. In addition, add-in files stored in the following directory will also appear in the list but will not be listed in the Registry:

C:\Documents and Settings\<username>\Application Data\Microsoft\AddIns

You can add a new AddIn object to the AddIns collection either manually or programmatically by using VBA. To add a new add-in to the collection manually, choose Tools ^ Add-Ins, click the Browse button, and locate the add-in.

To enroll a new member of the Addlns collection with VBA, use the collection's Add method. Here's an example:

Application.AddIns.Add "c:\files\newaddin.xla"

After the preceding instruction is executed, the Addlns collection has a new member, and the Add-Ins dialog box shows a new item in its list. If the add-in already exists in the collection, nothing happens, and an error is not generated.

If the add-in that you're enrolling is on removable media (for example, a floppy disk or CD-ROM), you can also copy the file to Excel's library directory with the Add method. The following example copies Myaddin.xla from drive A and adds it to the Addlns collection. The second argument (True, in this case) specifies whether the add-in should be copied. If the add-in resides on a hard drive, the second argument can be ignored.

Application.AddIns.Add "a:\Myaddin.xla", True

Enrolling a new workbook into the Addlns collection does not install it.To install the add-in,set its Installed property to True.

The Windows Registry does not actually get updated until Excel closes normally. Therefore, if Excel ends abnormally (that is, if it crashes), the add-in's name will not get added to the Registry, and the add-in will not be part of the Addlns collection when Excel restarts.

0 0

Post a comment