打包和分发 Excel 应用程序的最佳方式是什么
我编写了一个基于 Excel 的数据库报告工具。 目前,所有 VBA 代码都与单个 XLS 文件关联。 用户通过单击工具栏上的按钮来生成报告。 不幸的是,除非用户以其他文件名保存文件,否则所有报告的数据都会被清除。
当我在 Word 中创建类似的工具时,我可以将所有代码放入模板 (.dot) 文件中并从那里调用它。 如果我将模板文件放在 Office 启动文件夹中,则每次启动 Word 时都会启动该模板文件。 有没有类似的方法,在 Excel 中打包和分发我的代码? 我尝试过使用加载项,但没有找到从应用程序窗口调用代码的方法。
I've writen an Excel-based, database reporting tool. Currentely, all the VBA code is associated with a single XLS file. The user generates the report by clicking a button on the toolbar. Unfortunately, unless the user has saved the file under another file name, all the reported data gets wiped-out.
When I have created similar tools in Word, I can put all the code in a template (.dot) file and call it from there. If I put the template file in the Office startup folder, it will launch everytime I start Word. Is there a similar way, to package and distribute my code in Excel? I've tried using Add-ins, but I didn't find a way to call the code from the application window.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需将您的代码移至 Excel 插件 (XLA) - 该插件会在启动时加载(假设它位于 %AppData%\Microsoft\Excel\XLSTART 文件夹中),但如果它是插件,而不是工作簿,则只有您的宏和定义的启动函数将被加载。
如果函数依赖于电子表格本身,那么您可能需要使用模板和插件的组合。
我正在分发这样的应用程序的一部分,我们有 Word、Excel 和 Powerpoint(XLA、PPA、DOT)的插件以及 Office 2007“功能区”版本(DOTM、XLAM 和 PPAM)
插件启动代码创建工具栏按钮,如果没有找到它们,这意味着在任何工作簿/文档/等中,他们只需点击工具栏按钮即可运行我们的代码(我们有两个操作按钮和一个显示设置对话框的按钮)
模板并不是真正的方法对于 VBA 代码,插件绝对是最佳选择...
因此,为了在启动时加载工具栏,我们使用类似的东西..(检查工具栏是否存在 - 代码将为每个打开的工作表运行,但工具栏对于用户会话来说是持久的)
希望有帮助:)
Simply move your code into an Excel Addin (XLA) - this gets loaded at startup (assuming it's in the %AppData%\Microsoft\Excel\XLSTART folder) but if it's a addin, not a workbook, then only your macros and defined startup functions will be loaded.
If the functions depend on a spreadsheet itself, then you might want to use a combination of templates and addins.
I'm distributing part of an application like this, we have addins for Word, Excel and Powerpoint (XLA, PPA, DOT) and also Office 2007 'ribbon' versions (DOTM, XLAM and PPAM)
The addin startup code creates toolbar buttons if they're not found, this means in any workbook/document/etc they can simply hit the toolbar button to run our code (we have two action buttons and one button that displays a settings dialog)
Templates aren't really the way to go for VBA code, Addins are definitely the way to go...
So to load the toolbars on startup we're using something like.. (checking to see if toolbar exists though - code will run for each worksheet that is opened, but toolbars are persistent for the user session)
hope that helps :)
我总是使用插件(xla)/模板(xlt)组合。 您的加载项创建菜单(或其他 UI 入口点)并根据需要加载模板。 它还将您想要保留的数据写入数据库(Access、SQLServer、文本文件,甚至 xls 文件)。
第一条规则是将代码与数据分开。 然后,如果您以后有错误修复或其他代码更改,您可以发送新的加载项,并且它们的所有模板和数据库都不会受到影响。
I always use an Add-in(xla)/Template(xlt) combination. Your add-in creates the menu (or other UI entry points) and loads templates as needed. It also write data that you want to persist to a database (Access, SQLServer, text file, or even an xls file).
The first rule is to keep your code separate from your data. Then, if you later have bug fixes or other code changes, you can send a new add-in and all of their templates and databases aren't affected.
您可以修改用户的personal.xls 文件,该文件存储在excel 启动目录中(因Office 版本而异)。 如果你有很多用户,那可能会很麻烦。
解决问题的另一种方法是将宏存储在模板 (.xlt) 文件中。 然后,当用户打开它时,他们无法将其保存回原始文件,而必须指定一个新文件名来另存为。 此方法的缺点是,您会在每个保存的文件中获得原始代码的多个副本。 如果您修改原始 .xlt,并且有人在以前保存的 .xls 文件中重新运行旧宏,那么事情可能会失步。
You can modify the user's personal.xls file, stored in the excel startup directory (varies between Office versions). If you have lots of users though, that can be fiddly.
An alternative way to get over your problem is to store the macro in a template (.xlt) file. Then when the users opens it they can't save it back over the original file, but have to specify a new filename to save it as. The disadvantage of this method is that you then get multiple copies of your original code all over the place with each saved file. If you modify the original .xlt and someone reruns the old macro in a previously-saved .xls file then things can get out of step.
您是否研究过 ClickOnce 部署 Excel 文件?
Have you looked into ClickOnce deploying the Excel file?
如何将 Excel 保存到具有只读权限的网络文件夹? 可以使用集成的 Windows 身份验证来完成身份验证,并且无需在 VBA 中存储数据库的连接密码。 然后,您只需向您的用户分发一次指向此位置的链接。 如果您要进行更新,您只会更改该文件夹中的数据,而不会通知用户。
What about to save an excel to network folder with read only permissions ? The authentication can be done with integrated windows authentication and you don't need to store connection password to the database in the VBA. Then you only need distribute a link to this location to your users only once. If you will do an update, you only change data in that folder without user notice.