简体   繁体   English

在网络驱动器上共享 *.xlam - 调用 subs 和函数

[英]shared *.xlam on network drive - call subs and functions

I have been scouring the forum for a solution to my challenge below, bur unfortunately without any luck.我一直在论坛上搜索以下挑战的解决方案,但不幸的是没有任何运气。 I have written some subs and functions, that I need to make available to my colleagues and that I would like to be able to update centrally.我已经编写了一些 subs 和函数,我需要将它们提供给我的同事,并且我希望能够集中更新。 In order to do that, following this brilliant article, https://www.excelguru.ca/content.php?152-Deploying-Add-ins-in-a-Network-Environment , I have made a sheet that can deploy my code to an *.xlam on our network drive along with code to install the Add In on the users excel.为了做到这一点,在这篇精彩的文章https://www.excelguru.ca/content.php?152-Deploying-Add-ins-in-a-Network-Environment 之后,我制作了一张可以部署我的将代码添加到我们网络驱动器上的 *.xlam 以及在用户 excel 上安装加载项的代码。 To allow the users to call the subs/functions in the *.xlam, I have added a reference to the workbook-template where the subs/functions are needed.为了允许用户调用 *.xlam 中的子程序/函数,我添加了对需要子程序/函数的工作簿模板的引用。

But, as the Add In is located on the network drive, it will not always be available, and the user will get the compile error "Can't find the project or library".但是,由于 Add In 位于网络驱动器上,因此它并不总是可用,并且用户将收到编译错误“找不到项目或库”。

So, my questions are:所以,我的问题是:

  1. Is there a way to still use the reference method, but work around the "Can't find the project or library"-error?有没有办法仍然使用引用方法,但解决“找不到项目或库”错误?
  2. Is there a better way for the users to call functions from the Add In?有没有更好的方法让用户从 Add In 调用函数?
  3. And the big one: Should i share and update to code in a completely different manner?最重要的是:我应该以完全不同的方式共享和更新代码吗?

Best regards Knekse最好的问候 Knekse

Because:因为:

  1. An add-in can load another add-in.一个加载项可以加载另一个加载项。 Workbooks.Open(Filename:=pathToFile & addinFilename, ReadOnly:=True) Workbooks.Open(Filename:=pathToFile & addinFilename, ReadOnly:=True)
  2. The network resource will not always be reachable.网络资源并不总是可访问的。

You might try using a stub add-in on the client machines.您可以尝试在客户端计算机上使用存根加载项。

This stub can:这个存根可以:

  1. Check whether a desired add-in is available on the network, and load if possible.检查所需的加载项是否在网络上可用,并在可能的情况下加载。
  2. Option A: Provide stub functions/subs that call the real routines in the desired add-in when it's available, and otherwise return a suitable failure status or default message.选项 A:提供存根函数/子程序,当它可用时调用所需加载项中的实际例程,否则返回合适的失败状态或默认消息。
  3. Option B: Automatically copy the desired add-in to a cache on the local machine and add load the cached copy if needed.选项 B:自动将所需加载项复制到本地计算机上的缓存,并在需要时添加加载缓存副本。

By keeping the stub simple and well tested, it need not be frequently changed, so you won't lose the whole benefit of keeping the main add-in on the network.通过保持存根简单并经过充分测试,它不需要经常更改,因此您不会失去将主要加载项保留在网络上的全部好处。

Note that there is no need to add the networked add-in to the AddIns/AddIns2 collection;请注意,无需将联网加载项添加到 AddIns/AddIns2 集合中; you can just use Workbooks.Open(pathToAddIn, ReadOnly:=True).你可以只使用 Workbooks.Open(pathToAddIn, ReadOnly:=True)。 It will not show up in ‹‹File › Options › Add-Ins›› when opened this way.以这种方式打开时,它不会显示在‹‹文件›选项›插件››中。 Consequently, if you want to unload or reload the add-in without closing Excel, either your stub add-in should provide a way to do this, or you will need to do it with VBA (such as in the Immediate window of the VBA editor).因此,如果您想在不关闭 Excel 的情况下卸载或重新加载加载项,您的存根加载项应该提供一种方法来执行此操作,或者您需要使用 VBA 执行此操作(例如在 VBA 的立即窗口中)编辑)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM