如何在 VBA 代码中使用版本控制?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2996995/
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 to use version control with VBA code?
提问by user361283
I am developing a VBA application which is quite large. I want to use SVN for that application developing.
我正在开发一个非常大的 VBA 应用程序。我想使用 SVN 进行该应用程序的开发。
How can I split my modules from the Excel document and how to upload my modules separately to source control?
如何从 Excel 文档中拆分我的模块以及如何将我的模块分别上传到源代码管理?
Please help me.
请帮我。
回答by CodeKid
Check out this excel addin https://github.com/hilkoc/vbaDeveloper.
查看这个 excel 插件https://github.com/hilkoc/vbaDeveloper。
It exports all your vba code automatically, as soon as you save your workbook. You can also easily import it again, when you open a workbook. It all work very nicely.
保存工作簿后,它会自动导出所有 vba 代码。您还可以在打开工作簿时轻松地再次导入它。这一切都很好。
As a bonus, it comes with a code formatter that you can run within the vba editor, so you can format your code as you write.
作为奖励,它带有一个可以在 vba 编辑器中运行的代码格式化程序,因此您可以在编写代码时格式化代码。
回答by Chel
I wrote a small tool to help with putting VBA code under version control, withoutrequiring anything from Excel, or locking you into any specific version-control system. It can either extract modules from an Office file to a folder, or publish modules from a folder to an Office file. In either case it accesses the Office file directly, not through Excel. It's available on GitHub:
我编写了一个小工具来帮助将 VBA 代码置于版本控制之下,而无需 Excel 中的任何内容,也无需将您锁定在任何特定的版本控制系统中。它可以将模块从 Office 文件提取到文件夹,也可以将模块从文件夹发布到 Office 文件。在任何一种情况下,它都会直接访问 Office 文件,而不是通过 Excel。它可以在 GitHub 上找到:
Microsoft Office VBA code is usually held in binary format, making proper version control difficult. VBA Sync Tool synchronizes macros between a VBA-enabled file and a folder, enabling easy version control using Git, SVN, Mercurial, or any other VCS.
Microsoft Office VBA 代码通常以二进制格式保存,这使得正确的版本控制变得困难。VBA 同步工具在启用 VBA 的文件和文件夹之间同步宏,从而使用 Git、SVN、Mercurial 或任何其他 VCS 实现轻松的版本控制。
To start, select the Extract VBA from Office fileoption, then select the locations of your repository (or where you'd like to start one) and the Office file. The tool will compare the two locations and show all the differences:
首先,选择从 Office 文件中提取 VBA选项,然后选择存储库的位置(或您想要开始的位置)和 Office 文件。该工具将比较两个位置并显示所有差异:
If you want to extract everything (typical for setting up a repository), just click OK. If you want to be more selective, you can untick specific files (for example some form designs that you know haven't changed) and then proceed. If you set up a diff tool (under File → Settings), you can double-click on a module to view its changes.
如果您想提取所有内容(通常用于设置存储库),只需单击OK。如果您想更具选择性,您可以取消选中特定文件(例如您知道没有更改的某些表单设计),然后继续。如果您设置了差异工具(在文件 → 设置下),您可以双击模块以查看其更改。
After a merge, follow the same procedure, but select the Publish VBA to Office fileoption. When you hit Applyor OK, the tool will write the combined code into the Office file.
合并后,按照相同的步骤操作,但选择“将VBA 发布到 Office 文件”选项。当您点击Apply或OK 时,该工具会将组合代码写入 Office 文件。
回答by Mark Mayo
With file->export file you can export the individual classes.
使用文件-> 导出文件,您可以导出单个类。
That's one way to split the modules out - temporarily or otherwise.
这是拆分模块的一种方法 - 暂时或以其他方式。
Once you've done that, you can then create an SVN repository. I won't go into instructions for that as it's all over the internet, but here's a starting point:
完成后,您就可以创建一个 SVN 存储库。我不会详细说明,因为它遍布互联网,但这是一个起点:
回答by MarkJ
Check out this answeron how to automatically extract all modules/forms/classes to text files. Which will make them more manageable in SVN.
查看有关如何自动将所有模块/表单/类提取到文本文件的答案。这将使它们在 SVN 中更易于管理。