How to put Excel VBA into git

Viewed 20654

I've inherited some VBA in Excel and want to put it into git. As it stands, git sees it as binary and doesn't want to do file change deltas but duplicate the whole file.

I want to break the individual macros out into files to put them into git. Is there a standard way to do this?

4 Answers

If you use Rubberduck VBA, after clicking

Ready Button

You can use the file menu to "Export Active Project", which exports the form binaries and the code as BAS objects, which are just plain text. Then you can commit to git.

Tools -> Export Active Project

I had this problem and solved it by creating a VBA module to export other VBA modules. Usage instructions for this, and the raw code, can be found at the following location:

https://github.com/ColmBhandal/VbaSync.

C# Alternative

There is a C# alternative for putting VBA under Excel version control. The code has been added to a C# library which can be used to do version control e.g. via a CLI tool or via a VSTO AddIn:

https://gitlab.com/hectorjsmith/csharp-excel-vba-sync

Disclaimer

I was involved in the coding of the above repos. They are both free to use and open source.

Related