如何将代码更改保存到 Excel VBA 加载项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/889840/
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
How do i save code changes to an Excel VBA add-in?
提问by notnot
I've made an add-in for Excel in VBA and now I need to make changes to the code, but the file won't save. I open the .xlam file, I make the changes, ctrl-S to save with no errors popping up, close down. But when I reopen, none of the change I made are there. What gives? is there some special way I have to save an add-in to make changes stick?
我已经在 VBA 中为 Excel 制作了一个加载项,现在我需要对代码进行更改,但文件不会保存。我打开 .xlam 文件,进行更改,按 ctrl-S 进行保存,没有出现错误,然后关闭。但是当我重新打开时,我所做的任何更改都不存在。是什么赋予了?是否有一些特殊的方式我必须保存加载项才能使更改保持不变?
回答by Jon Peltier
In the VB editor, select the project in the Project Explorer pane, then in the Immediate Window (Ctrl + G) enter this line and press Enter:
在 VB 编辑器中,在 Project Explorer 窗格中选择项目,然后在 Immediate Window (Ctrl + G) 中输入此行并按 Enter:
ThisWorkbook.Save
此工作簿.保存
回答by Stewbob
I have had occurrences where it did not look like the Add-In was saved. I had to unload the Add-In, restart Excel, and then reload the Add-In. The saved changes were there, just not shown until the Add-In was reloaded.
我遇到过看起来似乎没有保存加载项的情况。我不得不卸载加载项,重新启动 Excel,然后重新加载加载项。保存的更改就在那里,只是在加载项重新加载后才显示。
回答by Andrew Scagnelli
I've had issues with add-ins not saving when the default Excel save is made; instead, you should make sure that you always save from inside the VBA editor. Beyond that, make sure you haven't checked the "Lock project for viewing" checkbox or added a password -- these can both be found on the "Protection" tab of the "Project Properties" dialog, the 5th item in the "tools" menu.
在进行默认 Excel 保存时,我遇到了加载项未保存的问题;相反,您应该确保始终从 VBA 编辑器内部进行保存。除此之外,请确保您没有选中“锁定项目以供查看”复选框或添加密码——这些都可以在“项目属性”对话框的“保护”选项卡上找到,“工具”中的第 5 项“ 菜单。
回答by BasilCinnamon
I have also had the issue that the VBE does not save code changes in a .xlam add-in I created. By chance I discovered that if there are any workbooks open (other than the hidden .xlam), the VBE save does not happen, but if all other workbooks are closed, then the VBE does save changes in the add-in. It's an awkward workaround to save and close all workbooks in order to save the code changes, then reopen them, but it is faster than always exporting the changed modules, closing Excel, reopening it and the VBE, and importing the saved .bas files. Maybe that gives someone (at Microsoft?) a hint of why the VBE isn't saving as it should.
我还遇到了 VBE 没有在我创建的 .xlam 加载项中保存代码更改的问题。我偶然发现,如果有任何工作簿打开(隐藏的 .xlam 除外),则 VBE 保存不会发生,但如果所有其他工作簿都关闭,则 VBE 会保存加载项中的更改。保存和关闭所有工作簿以保存代码更改,然后重新打开它们是一种尴尬的解决方法,但它比总是导出更改的模块、关闭 Excel、重新打开它和 VBE 以及导入保存的 .bas 文件要快。也许这让某人(在 Microsoft?)暗示了为什么 VBE 没有按应有的方式进行保存。