如何使用 msi 安装程序部署 VBA Excel 加载项 (foo.xlam)?
我是一名 C# 开发人员,正在将同事的 VBA Excel 加载项(.xlam 文件)与我的 msi 安装程序(如果需要的话,使用 VS 部署项目构建)捆绑在一起。 .xlam 放置在应用程序文件夹 (C:\Program Files (x86)\MyCompany\TheProduct) 目录中。用户被迫导航到 Excel 选项 >加载项>管理 Excel 加载项转到...>>浏览,然后强制导航到上面列出的安装目录。浏览屏幕默认目录是%APPDATA%\Microsoft\AddIns。
有没有办法让我无需点击就能自动启用此 VBA 插件?
预先感谢,
弗兰克
I am a C# developer who is bundling a colleague's VBA Excel Add-In (.xlam file) with my msi installer (built using a VS Deployment project if that matters). The .xlam is placed in the application folder (C:\Program Files (x86)\MyCompany\TheProduct) directory. Users are forced to navigate to Excel Options > Add-Ins > Manage Excel Add-Ins Go... > Browse and are then forced to navigate to the install directory listed above. The Browse screen default directory is %APPDATA%\Microsoft\AddIns.
Is there a way for me to automatically enable this VBA Add-In without all of the clicking?
Thanks in advance,
Frank
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我创建了一个自动安装过程,将其添加到 XLAM 文件的“此工作簿”部分,以便在文件打开时自动运行。
为了区分安装文件和已安装文件,安装版本命名为“.install.xlam”,安装版本命名为“.xlam”。 (否则Excel出现“抱歉,Excel无法同时打开两个同名的工作簿。”
过程:
– 使用 .install.xlam 重命名您的 XLAM 文件
– 打开它并在 Visual Basic 编辑器 (VBE) 中进行编辑
– 将以下过程添加到 VBE 中的“此工作簿”部分
– 保存文件
为了共享/安装 XLAM,您现在只需要求用户双击 XLAM 文件,根据需要启用宏并接受安装插件。
如果您想稍后更新 XLAM,只需双击它,根据需要启用宏并拒绝安装即可。然后编辑它并保存更改。
以下是添加到“ThisWorkbook”的代码:
I created an automatic install procedure to be added to the “This Workbook” section of the XLAM file, so that it’s automatically run when file is open.
In order to differentiate the installation file and the installed file, the install version is named “.install.xlam” and the installed version is just named “.xlam”. (Otherwise Excel has an “Sorry, Excel can’t open two workbooks with the same name at the same time.”
Procedure:
– Rename your XLAM file with .install.xlam
– Open it and edit in Visual Basic Editor (VBE)
– Add the following procedures to the “This workbook” section in VBE
– Save your file
In order to share/install your XLAM, you now just have to ask the user to double-click the XLAM file, enable macros as needed and accept to install the Add-In.
If you want to update your XLAM later on, you just double-click it, enable macros as needed and refuse to install it. Then edit it and save the changes.
Here is the code to add to “ThisWorkbook”:
这通常涉及更新注册表的 HKCU 部分(当您在 Excel 选项中手动检查插件时会发生这种情况)。但是,我有时会使用 Excel 安装目录中的 XLStart 文件夹。如果您的插件类型正确,Excel 将在启动时为系统上的所有用户加载该插件,并且他们无法选择将其关闭。有时这是可以接受的。就部署而言,它要容易得多。
This normally involves updating the HKCU section of the registry (this is what happens when you manually check the addin in the Excel options). However, I sometimes use the XLStart folder in Excel's installation directory. Provided your addin is the right type it will be loaded by Excel on launch for all users on the system, and they have no option to turn it off. Sometimes this is acceptable. Deployment wise it is much easier.
您可以将此代码插入“ThisWorkBook”工作表中的 *.xlam 中,只需打开此代码即可安装并激活当前的 AddIns
you can insert this code in your *.xlam in the sheet "ThisWorkBook" this code install and activate the current AddIns, just by opening
Windows Installer 对此没有直接支持。因此,您要么使用一些自定义操作,要么购买一个为安装 Office 加载项提供直接支持的工具。
Windows Installer doesn't have direct support for this. So either you use some custom actions or you buy a tool which offers direct support for installing Office add-ins.