我已经编写了一个安装程序(在VBA中)以安装或重新安装Excel .xlam加载项,包括如果已经安装了加载项,请更改安装位置。
该插件(我们将其称为“ MyAddin”)为多个用户提供了UDF功能。由于VBA UDF和工作簿链接(在其他地方-Excel add-in UDF path issue中有问题)的问题,我们将所有用户的插件安装到公共位置C:\ ExcelAddins \ MyAddin \,而不是%AppData%\ Microsoft \ AddIns \ < / p>
Dim oAddInOld As Excel.AddIn
Dim oAddInNew As Excel.AddIn
Dim FSO as new scripting.FileSystemObject
const srcePath as string = "G:\Repository\MyAddin.xlam"
const destPath as string = "C:\ExcelAddins\MyAddin\MyAddin.xlam"
const destFldr as string = "C:\ExcelAddins\MyAddin"
const addinName as string = "MyAddin.clam"
' iterated through installed addins to find already installed
For each oAddInOld In Application.AddIns
If oAddInOld.name = addinName then
oAddInOld.Installed = False
'Even attempt to nuke it from the registry.
' Code not included, but is working
' has some smarts around identifying which OPEN item
' corresponds to this addin.
' oReg.DeleteValue HKEY_CURRENT_USER, _
' "SOFTWARE\Microsoft\Office\15.0\Excel\Options", "OPEN1"
DeleteAddinFromRegistry addinName
end if
Next oAddInld
'Create the new addin folder and copy the new version there
FSO.CreateFolder destFldr '(actual code is a little smarter)
FSO.CopyFile srcePath, destPath
'Install the new addin in the new folder (Tried CopyFile:=True and CopyFile:=False)
Set oAddIn = Application.AddIns.Add(destPath , CopyFile:=False)
'Enable the addin
oAddIn.Installed = True
MsgBox "Addin Installed. Please save your work and restart excel"
除非外接程序已经安装在其他位置(例如%AppData%\ Microsoft \ AddIns),否则安装程序将正常运行。在这种情况下,位置不会自动更改。用户需要在“ Excel加载项”对话框中选择“浏览”按钮,然后浏览到新位置-这意味着安装程序实质上是美化的文件复印机。
有没有一种方法可以完全自动化此过程而无需人工干预?外接程序已在全球范围内推出,大多数用户已经将其安装在旧位置%AppData%\ Microsoft \ AddIns中。
p.s。 VBScript被全局禁用。否则我会找到解决方案的。