使用VBA更新xlam加载项 [英] Updating an xlam add-in using VBA

查看:653
本文介绍了使用VBA更新xlam加载项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  Sub Install_Addin()

Dim AI as excel.addin
设置AI = Application.Addins.Add(C:\Add_In。 xlam)
AI.Installed = True
Application.Addins(Add_in)Installed = True

End Sub
/ pre>

以上是我从Chip Pearson得到的代码,用于安装Excel的加载项。这段代码第一次运行良好。我的加载项有一个控件按钮(我在编写加载项时修改了xml),所以当安装加载项时(使用上面的代码),一个按钮自动出现在我的excel功能区上,然后我可以使用我的加载项。



问题是当我尝试重新安装我的加载项。当我更新我的加载项的代码,并尝试使用上述代码重新安装时,我收到这个错误----

 运行时错误'1004'
无法将外接程序复制到库

这是因为加载项在重新安装之前未正确卸载。而且我放弃了在Web上搜索一种使用VBA代码来解除加载项的方法。我找不到任何简单的解决方案。



现在,卸载加载项的唯一方法是手动执行。首先我从Microsoft Add ins文件夹中删除加载项。然后我打开Excel,它给我一个警告信息,它找不到加载项。然后我去加载项管理器,点击我的加载项,然后点击去。然后在加载项列表中,我勾选我的加载项,然后excel说加载项不存在,从列表中删除?然后加载项终于被删除。



只有手动删除这样的加载项,我可以使用上面的代码重新安装我的加载项。现在这真的很麻烦,特别是当我想向其他人分发加载项时。必须有一个更简单的方式来更新加载项,而无需首先手动删除它。



请不要提供随机的答案或答案,你认为可能是正确的对这个问题。也请不要告诉我试试这个。只有知道正确的解决方案,请告诉我。我已经尝试过一些事情,无济于事。如果你正在改变的话,那么这个例子就是:

非常感谢

解决方案

XLAM中的代码,但保持其名称和位置相同,您不需要将其重新安装为加载项。



如果要卸载现有的加载项,您可以使用不同的名称安装新版本,您可以将现有加载项的已安装属性设置为False,但是将现有的加载项保留在可用但未安装的加载项列表中。



如果要更改插件的名称或位置,更好的解决方案是使用存根加载器来简化返回和加载问题。您可以从我的网站 http://www.decisionmodels.com/downloads.htm下载开源工作示例


Sub Install_Addin()

   Dim AI as excel.addin
   Set AI = Application.Addins.Add("C:\Add_In.xlam")
   AI.Installed = True
   Application.Addins("Add_in").Installed = True

End Sub

Above is the code I got from Chip Pearson to install an Add-in to excel. This code works well for the first time. My add-in has a control button (I modifed the xml while writing the add-in) and so, when the add-in is installed (using the above code) a button automatically appears on my excel ribbon, and then I can use my add-in.

The problem is when I try re-installing my add-in. When I update the code of my add-in and try to re-install using the above code, I get this error ----

runtime error '1004'
Unable to copy add-in to library

This happens because the add-in is not properly uninstalled before it can be re-installed. And I have given up searching the web for a method to unistall an add-in using VBA code. I couldnt find any simple solution.

Right now the only way to un-install my add-in is to do it manually. First I delete the add-in from the Microsoft Add ins folder. Then I open Excel and it gives me a warning message that it could not find the add-in. Then I go to Add-in manager and click on my add-in and then click go. Then on the list of add-ins I tick my add-in and then excel says "Add-in not present. Delete from list?" and then the add-in is finally deleted.

Only after manually deletting the add-in like this, can I re-install my add-in using the above code. Now this is really cumbersome, especially when I want to distribute the add-in to other people. There has to be an easier way to update the add-in without having to first manually deleting it.

Please dont provide random answers or answers you think "might" be correct to this question. Also please dont tell me to "try out this and that". Only if you know the correct solution, tell me about it. I have already tried a number of things to no avail. :)

Thanks a lot.

解决方案

If you are changing the code in the XLAM but keeping its name and location the same you don't need to reinstall it as an addin.

If you want to uninstall an existing addin so that you can install a new version with a different name you can set the Installed property of the existing addin to False, but this leaves the existing addin in the list of available but not installed addins.

If you want to change the name or location of the addin a better solution is to use a stub addin loader to simplify reversioning and loading issues. You can download an open source working example from my website at http://www.decisionmodels.com/downloads.htm

这篇关于使用VBA更新xlam加载项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆