对 MS Excel 进行版本控制的最佳方法 [英] Best way to do Version Control for MS Excel

查看:31
本文介绍了对 MS Excel 进行版本控制的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您在 MS Excel (2003/2007) 中使用过哪些版本控制系统?你会推荐什么? 为什么?您发现最受好评的版本控制系统有哪些限制?

What version control systems have you used with MS Excel (2003/2007)? What would you recommend and Why? What limitations have you found with your top rated version control system?

为了正确看待这一点,这里有几个用例:

To put this in perspective, here are a couple of use cases:

  1. VBA 模块的版本控制
  2. 有不止一个人在处理 Excel 电子表格,而且他们可能正在对同一个工作表进行更改,而他们想要合并和集成这些工作表.此工作表可能包含公式、数据、图表等
  3. 用户不太懂技术,使用的版本控制系统越少越好
  4. 空间限制是一个考虑因素.理想情况下,只保存增量更改而不是整个 Excel 电子表格.

推荐答案

我刚刚设置了一个使用 Bazaar 的电子表格,并通过 TortiseBZR 手动签入/签出.鉴于该主题帮助我完成了保存部分,我想在这里发布我的解决方案.

I've just setup a spreadsheet that uses Bazaar, with manual checkin/out via TortiseBZR. Given that the topic helped me with the save portion, I wanted to post my solution here.

我的解决方案是创建一个电子表格,在保存时导出所有模块,并在打开时删除并重新导入模块.是的,这对于转换现有电子表格可能存在潜在危险.

这允许我通过 Emacs(是的,emacs)或在 Excel 中编辑模块中的宏,并在重大更改后提交我的 BZR 存储库.因为所有模块都是文本文件,所以 BZR 中的标准 diff 样式命令适用于我的源,除了 Excel 文件本身.

This allows me to edit the macros in the modules via Emacs (yes, emacs) or natively in Excel, and commit my BZR repository after major changes. Because all the modules are text files, the standard diff-style commands in BZR work for my sources except the Excel file itself.

我已经为我的 BZR 存储库设置了一个目录,X:DataMySheet.在 repo 中有 MySheet.xls 和我的每个模块的一个 .vba 文件(即:Module1Macros).在我的电子表格中,我添加了一个模块,该模块不受名为VersionControl"的导出/导入周期的影响.每个要导出和重新导入的模块都必须以宏"结尾.

I've setup a directory for my BZR repository, X:DataMySheet. In the repo are MySheet.xls and one .vba file for each of my modules (ie: Module1Macros). In my spreadsheet I've added one module that is exempt from the export/import cycle called "VersionControl". Each module to be exported and re-imported must end in "Macros".

VersionControl"模块的内容:

Sub SaveCodeModules()

'This code Exports all VBA modules
Dim i%, sName$

With ThisWorkbook.VBProject
    For i% = 1 To .VBComponents.Count
        If .VBComponents(i%).CodeModule.CountOfLines > 0 Then
            sName$ = .VBComponents(i%).CodeModule.Name
            .VBComponents(i%).Export "X:ToolsMyExcelMacros" & sName$ & ".vba"
        End If
    Next i
End With

End Sub

Sub ImportCodeModules()

With ThisWorkbook.VBProject
    For i% = 1 To .VBComponents.Count

        ModuleName = .VBComponents(i%).CodeModule.Name

        If ModuleName <> "VersionControl" Then
            If Right(ModuleName, 6) = "Macros" Then
                .VBComponents.Remove .VBComponents(ModuleName)
                .VBComponents.Import "X:DataMySheet" & ModuleName & ".vba"
           End If
        End If
    Next i
End With

End Sub

接下来,我们必须为打开/保存设置事件挂钩以运行这些宏.在代码查看器中,右键单击ThisWorkbook"并选择查看代码".您可能需要拉下代码窗口顶部的选择框才能从(常规)"视图更改为工作簿"视图.

Next, we have to setup event hooks for open / save to run these macros. In the code viewer, right click on "ThisWorkbook" and select "View Code". You may have to pull down the select box at the top of the code window to change from "(General)" view to "Workbook" view.

工作簿"视图的内容:

Private Sub Workbook_Open()

ImportCodeModules

End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

SaveCodeModules

End Sub

我将在接下来的几周内适应这个工作流程,如果我有任何问题,我会发布.

I'll be settling into this workflow over the next few weeks, and I'll post if I have any problems.

感谢分享 VBComponent 代码!

Thanks for sharing the VBComponent code!

这篇关于对 MS Excel 进行版本控制的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆