Removing Add-ins programmatically from Excel 2003 using VBScript  
Author Message
inja





PostPosted: Mon Aug 29 11:38:14 CDT 2005 Top

Excel Programming >> Removing Add-ins programmatically from Excel 2003 using VBScript

I have a small VBScript that uses Excel Automation Server to install [and
update] an XLA file. Within the same package, I also provide an UnInstall
routine.

I have 2 problems:

1) To get rid of the XLA, I cannot use "Application.AddIns.Remove(<ref>)"
*since this method is unknown to VBA* but I have to issue an
"Application.AddIns(<ref>).Installed = False" first and then, after I quit
Excel Automation server, to physically delete the file. After that, the
Add-In does not load anymore but it still appears in my Add-Ins list; Excel
will delete it only after I click on the 'invalid' entry. Is there a way
(without going thru the registry) to really get rid of Add-Ins
programmatically?

2) If I issue an "Application.AddIns(<ref>).Installed = False" and next
issue an "Application.AddIns.Add" with the same XLA but from a different
folder, Excel continues to link the first one. Is there a way to update the
Add-ins programmatically so that I link the right one?

I have seen that Excel continues to swap Add-ins from the registry key
"HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Options" for those
loaded and installed ('OPEN', 'OPEN1', 'OPEN2', ...) the key
"HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Add-in Manager" for
those loaded but not installed (using the internal name of the Add-in, for
instance 'My Addin').

Could not find any relevant info on MSDN/Microsoft.

Help needed

Excel256  
 
 
Tom





PostPosted: Mon Aug 29 11:38:14 CDT 2005 Top

Excel Programming >> Removing Add-ins programmatically from Excel 2003 using VBScript You have to remove it from the registry (I assume you will do this with
code). There is no built in support for it in VBA.

--
Regards,
Tom Ogilvy



> I have a small VBScript that uses Excel Automation Server to install [and
> update] an XLA file. Within the same package, I also provide an UnInstall
> routine.
>
> I have 2 problems:
>
> 1) To get rid of the XLA, I cannot use "Application.AddIns.Remove(<ref>)"
> *since this method is unknown to VBA* but I have to issue an
> "Application.AddIns(<ref>).Installed = False" first and then, after I quit
> Excel Automation server, to physically delete the file. After that, the
> Add-In does not load anymore but it still appears in my Add-Ins list;
Excel
> will delete it only after I click on the 'invalid' entry. Is there a way
> (without going thru the registry) to really get rid of Add-Ins
> programmatically?
>
> 2) If I issue an "Application.AddIns(<ref>).Installed = False" and next
> issue an "Application.AddIns.Add" with the same XLA but from a different
> folder, Excel continues to link the first one. Is there a way to update
the
> Add-ins programmatically so that I link the right one?
>
> I have seen that Excel continues to swap Add-ins from the registry key
> "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Options" for those
> loaded and installed ('OPEN', 'OPEN1', 'OPEN2', ...) the key
> "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Add-in Manager"
for
> those loaded but not installed (using the internal name of the Add-in, for
> instance 'My Addin').
>
> Could not find any relevant info on MSDN/Microsoft.
>
> Help needed


 
 
DutchGemini





PostPosted: Tue Aug 30 02:22:02 CDT 2005 Top

Excel Programming >> Removing Add-ins programmatically from Excel 2003 using VBScript Thx alot, let's hope MS adds this missing method to its AddIns collection and
allows one to refresh some. Apart from that, having to manually go to the
list and clicking 'Ok' to remove is imho really a bad approach...

Dutch



> You have to remove it from the registry (I assume you will do this with
> code). There is no built in support for it in VBA.
>
> --
> Regards,
> Tom Ogilvy
>


> > I have a small VBScript that uses Excel Automation Server to install [and
> > update] an XLA file. Within the same package, I also provide an UnInstall
> > routine.
> >
> > I have 2 problems:
> >
> > 1) To get rid of the XLA, I cannot use "Application.AddIns.Remove(<ref>)"
> > *since this method is unknown to VBA* but I have to issue an
> > "Application.AddIns(<ref>).Installed = False" first and then, after I quit
> > Excel Automation server, to physically delete the file. After that, the
> > Add-In does not load anymore but it still appears in my Add-Ins list;
> Excel
> > will delete it only after I click on the 'invalid' entry. Is there a way
> > (without going thru the registry) to really get rid of Add-Ins
> > programmatically?
> >
> > 2) If I issue an "Application.AddIns(<ref>).Installed = False" and next
> > issue an "Application.AddIns.Add" with the same XLA but from a different
> > folder, Excel continues to link the first one. Is there a way to update
> the
> > Add-ins programmatically so that I link the right one?
> >
> > I have seen that Excel continues to swap Add-ins from the registry key
> > "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Options" for those
> > loaded and installed ('OPEN', 'OPEN1', 'OPEN2', ...) the key
> > "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Excel\Add-in Manager"
> for
> > those loaded but not installed (using the internal name of the Add-in, for
> > instance 'My Addin').
> >
> > Could not find any relevant info on MSDN/Microsoft.
> >
> > Help needed
>
>
>
 
 
DutchGemini





PostPosted: Tue Aug 30 09:00:07 CDT 2005 Top

Excel Programming >> Removing Add-ins programmatically from Excel 2003 using VBScript This happens installing and uninstalling Add-In in Excel via VBA/VBScript:

Installing:
======
1) When you add an Add-In via VBA/VBScript using 'Application.AddIns.Add
<file>, CopyFile := True' and the source file is on a local drive, the Add-In
is linked to Excel but not copied.

2) When you add an Add-In via VBA/VBScript using 'Application.AddIns.Add
<file>, CopyFile := True' and the source file is *NOT* on a local drive, the
Add-In is linked to Excel after being copied to the
'%AppData%\Microsoft\AddIns' folder

In both cases you end up with an entry called "OPEN" (evt. followed by a
number) under "HKCU\Software\Microsoft\Office\<Version>\Excel\Options" that
contains:
a) the full path for 1)
b) only the name of the file for 2)

Uninstalling:
======
The only way to uninstall via VBA/VBScript is using
'Application.AddIns(<ref>).Installed = False'. However, the file remains
'visible' to Excel.

1) If the source file was *NOT* copied, the Add-In entry "OPEN" under
"HKCU\Software\Microsoft\Office\<Version>\Excel\Options" is removed and
another one is created under
"HKCU\Software\Microsoft\Office\<Version>\Excel\Add-in Manager" but having,
as a registry value, the full name of the file (for instance "C:\My
Folder\MyAddIn.xla")

2) If the source file was copied to the 'AppData' folder, the Add-In entry
"OPEN" under "HKCU\Software\Microsoft\Office\<Version>\Excel\Options" is
removed. *NO* extra entry is created under
"HKCU\Software\Microsoft\Office\<Version>\Excel\Add-in Manager"

Removing the Add-In
======
1) The file needs to be 'unRegistered'. Since 'Wscript.Shell' object cannot
handle the backslash '\' character, the only way to remove it is by using WMI
statements

Const HKEY_CURRENT_USER = &H80000001
ExcelRegistryKey = "Software\Microsoft\Office\<Version>\Excel\Add-in Manager"
Set WmiRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
Result = WmiRegistry.DeleteValue(HKEY_CURRENT_USER, ExcelRegistryKey, "C:\My
Folder\MyAddIn.xla")

The file does not have to be removed physically. Excel will not find it
anymore.

2) The file must be physically removed from the 'AppData' folder; this can
be done with the '.DeleteFile' method of a 'FileSystemObject'.

Hope this helps