

git/hooks folder inside your repository and add the following code: oletools can be installed via pip, Python’s package manager: pip install -U oletools.Ĭreate a file named pre-commit.py in the. Our script requires Python 3 and oletools.


Thus, we no longer have to resort to Excel itself to get hold of the VBA code. We use the Python package oletools to extract the VBA code from the Excel file (in fact, this works for any MS Office file). add these VBA files to your commit via git add.extract the VBA modules from your workbook and write them as.We will use the pre-commit hook to do the following when you call git commit: You can find a list of available hooks in. Hooks are programs you can place in a hooks directory to trigger actions at certain points in Git’s execution. Distributing the export function (either via copy and paste or as an Addin) and ensuring it runs reliably is another pain point.Īn alternative approach is to exploit Git’s built-in hooks. You are dependent on Excel, so if you copy your workbook from an email or another folder into your Git repository folder, your VBA export function will not run. There are a few downsides to using Excel events. You end up with your VBA files alongside your workbook which can then be pushed to your Git server. Every time you hit “save” in Excel, some VBA code is executed and saves a copy of your workbook’s VBA content to the filesystem. One common way to achieve this is via Excel’s Workbook.AfterSave (or Workbook.BeforeSave) event. The goal is to end up with a separate files for each of your VBA modules so that you can benefit from the Git functionalities. frm files is a simple and effective way to make Git aware of code inside your Excel workbooks. Exporting your VBA modules into stand-alone.
