vba XLAM / XLA 插件:有更好的方法吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5722020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XLAM / XLA Addins: is there a better way?
提问by tpascale
This post is about installing XLAM's without creating links. (Everyone hates links). Consider the trivial addin:
这篇文章是关于在不创建链接的情况下安装 XLAM。(每个人都讨厌链接)。考虑微不足道的插件:
Public Function UDF_HELLO(x)
UDF_HELLO = "Hello " & x
End Function
Put this code and nothing else into a Module and save as "Hello.xlam" on the Desktop (and NOT in the default excel addins folder). Next, while HELLO.XLAM is still open, create a new XLSX workbook with the formula
将此代码和其他任何内容放入模块中,并在桌面上保存为“Hello.xlam”(而不是在默认的 excel 插件文件夹中)。接下来,在 HELLO.XLAM 仍处于打开状态时,使用公式创建一个新的 XLSX 工作簿
=UDF_Hello("world")
in cell A1, which simply displays "Hello world" in that cell. Save the workbook and exit Excel. Now, if you reopen the workbook without the XLAM, Excel will complain about "links to other sources ...". Whether you click "Update" or "Don't Update", Excel will mangle the formula in cell A1 like this:
在单元格 A1 中,它只是在该单元格中显示“Hello world”。保存工作簿并退出 Excel。现在,如果您在没有 XLAM 的情况下重新打开工作簿,Excel 会抱怨“链接到其他来源......”。无论您单击“更新”还是“不更新”,Excel 都会像这样修改单元格 A1 中的公式:
='C:\Documents and Settings\tpascale\Desktop\Hello.xlam'!UDF_Hello("world")
Very often this "forced-linkage" is NOT desirable. In my computing environment there is a lot of ad-hoc analysis and it makes no sense to impose an install regimen on every XLAM we throw together to solve the problem of the day. I just want to hand out XLAM files to users and let those users open them when they need them, WITHOUT having to worry about the slightest mis-step causing their formulas to get mangled.
很多时候这种“强制链接”是不可取的。在我的计算环境中,有很多临时分析,在我们为解决当前问题而拼凑的每个 XLAM 上强加安装方案是没有意义的。我只想将 XLAM 文件分发给用户,让他们在需要时打开它们,而不必担心最轻微的错误步骤会导致他们的公式被破坏。
QUESTION:
题:
Is there a way to instruct Excel to NEVER construct external links for UDFs, and simply to use UDFs if they're loaded and return #VALUEs otherwise ?
有没有办法指示 Excel 永远不要为 UDF 构造外部链接,并且只是在加载 UDF 时使用它们,否则返回 #VALUEs ?
采纳答案by Govert
I don't know of a way around this with .xla/.xlam add-ins.
我不知道使用 .xla/.xlam 加载项解决此问题的方法。
But this issue does not occur with .xll add-ins. These can be created in C using the Excel 2010 SDK, or in managed languages like VB.NET or C# using the free Excel-DNAlibrary.
但 .xll 加载项不会出现此问题。这些可以使用Excel 2010 SDK在 C 中创建,或者使用免费的Excel-DNA库在 VB.NET 或 C# 等托管语言中创建。
(Disclaimer: I'm the developer of Excel-DNA. This issue is one of the reasons I went with the .xll interface for making managed UDF add-ins.)
(免责声明:我是 Excel-DNA 的开发人员。这个问题是我使用 .xll 界面制作托管 UDF 加载项的原因之一。)
回答by Jon49
You can have them open the .xla file and have an Auto_Open procedure install the add-in.
您可以让他们打开 .xla 文件并让 Auto_Open 过程安装加载项。
http://www.vbaexpress.com/kb/getarticle.php?kb_id=693
http://www.vbaexpress.com/kb/getarticle.php?kb_id=693
After excel closes you can have the add-in uninstall itself.
excel 关闭后,您可以让加载项自行卸载。
oAddIn.Installed = False
You can give your add-in a setting for the user to not uninstall after every use by using a worksheet named something then have cell A1 equal to true or false.
您可以通过使用名为 something 的工作表为您的加载项设置一个设置,以便用户在每次使用后不卸载,然后让单元格 A1 等于 true 或 false。
I haven't tested this but hopefully it works for you.
我还没有测试过这个,但希望它对你有用。
回答by JS20'07'11
This should work to resolve your issue though it does not instruct Excel regarding external links. I have tested it myself by creating the XLAM, saving it to my desktop, installing it in the Excel add-ins and then using it on a new workbook.
这应该可以解决您的问题,尽管它不会向 Excel 指示有关外部链接的信息。我已经通过创建 XLAM、将它保存到我的桌面、将它安装在 Excel 加载项中然后在新工作簿上使用它来自己测试它。
Steps:
脚步:
- Once you have saved the add-in, close it.
- Go to Excel Options-->Add-Ins
- In the Manage drop-down select Excel Add-ins and press 'Go'
- In the 'Add-Ins'dialogue that appears click 'Browse' and navigate to the add-in you just created. Select it and hit 'Ok'
- If prompted to save the add-in in the add-ins folder, select 'No'. Selecting 'Yes' may cause an error if the add-in file suffix does not match the version of Excel being used.
- Your add-in should appear in the 'Add-Ins available' scrollbox, check its box and hit 'Ok'
- Your add-in should now be active whenever you open Excel.
- Test this by opening a new workbook and try using your UDF.
- 保存加载项后,将其关闭。
- 转到 Excel 选项--> 加载项
- 在管理下拉列表中选择 Excel 加载项并按“开始”
- 在出现的“加载项”对话框中,单击“浏览”并导航到您刚刚创建的加载项。选择它并点击“确定”
- 如果提示将加载项保存在加载项文件夹中,请选择“否”。如果加载项文件后缀与正在使用的 Excel 版本不匹配,则选择“是”可能会导致错误。
- 您的加载项应出现在“可用加载项”滚动框中,选中其框并点击“确定”
- 每当您打开 Excel 时,您的加载项现在都应该处于活动状态。
- 通过打开一个新工作簿并尝试使用您的 UDF 来测试这一点。
Best,
最好的事物,
回答by Lun
I usually solve this problem by:
我通常通过以下方式解决这个问题:
- Saving an XLA/XLAM file (outside Personal folder, of course)
- Connect to it in Tools - Addins
- Write pseudo macros in your current Excel file that links to those macros / functions in the XLA/XLAM file.
- 保存 XLA/XLAM 文件(当然在个人文件夹之外)
- 在工具中连接到它 - 插件
- 在您当前的 Excel 文件中编写伪宏,链接到 XLA/XLAM 文件中的那些宏/函数。
See the detailed instructions in my reply here.
请参阅此处回复中的详细说明。