Click here to Skip to main content
15,348,965 members
Articles / Programming Languages / VBScript
Posted 15 Mar 2007


43 bookmarked


Rate me:
Please Sign up or sign in to vote.
4.47/5 (13 votes)
5 Apr 2008GPL34 min read
VBE IDE addin for comparing and versioning VBA using SVN or CVS


SourceTool is a utility-addin for:

  1. Extracting and loading source code from and to Excel workbooks, templates and add-ins
  2. Comparing source code between different versions of above
  3. Committing, updating, reverting and comparing source code into a version control system different from VSS (currently only SVN through TortoiseSVN is supported)

Most of the functionality builds upon Rob Boveys famous CodeCleaner addin, which was abused as a "SourceStripper" here.

The various functions can be accessed in the VBA IDE from the toolbar "Source":

Screenshot - clip_image002.jpg
  • The first button is used to open a project or a selected component of a project (common module, class module or userform). When opening, a folder selection dialog allows to choose the directory where to load the components from, saving is automatically done into a folder called <Excelfilename>.src in the same directory as the Excel file:

    Screenshot - clip_image004.jpg

  • The second button is used to save a project or a selected component of a project (common module, class module or user form).
  • The third button allows to select a different version of the selected project (this only works for projects as a whole) and shows the differences using a pre-configured difference viewer (currently WinMerge 2.4.6).

After the separator, the rest of buttons are all used for version control:

  • The fourth button invokes the tool to check for differences between the current copy (in memory) of the whole project or selected component with the base version in the repository.
  • The fifth button updates the whole project or selected component from the repository, notifying any conflicts.
  • The sixth button commits the whole project or selected component to the repository, asking for a log message before.
  • Finally, the seventh button reverts the whole project or selected component from the repository.

Installation and Configuration

First you need to install tortoiseSVN and subversion (in case you don't connect to a net-based repository already).

Then you need to install WinMerge to use the diff utility.

Finally, installation is completed by simply copying SourceTools.xla into your XLStart folder. You also have to enable access to VB project in the menu: Tools/ Macro/ Security, tab "Trusted Sources", checkbox "Trust access to Visual Basic Project".

Configuration is done in module MGlobals using mainly the following six constants:

' SVN control commands, if needed, replace with other

Public Const COMMITCMD = "C:\Programme\TortoiseSVN\bin\TortoiseProc.exe
    /command:commit /notempfile /path:"
Public Const UPDATECMD = "C:\Programme\TortoiseSVN\bin\TortoiseProc.exe
    /command:update /rev /notempfile /path:"
Public Const REVERTCMD = "C:\Programme\TortoiseSVN\bin\TortoiseProc.exe
    /command:revert /notempfile /path:"
Public Const DIFFCMD = "C:\Programme\TortoiseSVN\bin\TortoiseProc.exe
    /command:diff /path:"
Public Const PATHCONCAT = "*"
Public Const DIFFERCMD = "C:\Programme\WinMerge\WinMergeU.exe "

However, I'm sure that further customization will be needed in case a different version control system is used.


The first thing to do is to save the sources of the project by clicking the second button. This should create a directory called <Workbook/AddinName>.src with all components of your project as text files in it (named *.bas for plain modules, *.cls for classes, *.frm/*.frx for userforms and *.xwk for the Workbook's and Worksheet's code). So essentially everything you would get when exporting your components individually.

Then you should import BOTH the Workbook/Addin AND the <Workbook/AddinName>.src folder into a repository of your choice (on or your private/local one (that's when you need to download SVN itself, in case you don't want/need a repository for yourself, forget the SVN download, Tortoise is enough).

After that, DELETE the Workbook/Addin AND the *.src folder (or better, move them into a safe place, if the following checkout fails). Once you have deleted these files/folder, then CHECKOUT the files you have just imported into the folder (or any other folder, but that means you're changing the location of your addin/workbook).

Bear in mind, this is ALL still done OUTSIDE the Sourcetool, using plain TortoiseSVN functionality.
Now you're ready to use the SourceTool: Simply edit your project in the way you were used to, once finished click the commit button on the sourcetool toolbar in the VBA-IDE (button six) and you'll be presented the Tortoise commit dialog, showing either:

  1. All the components that changed since the last update (in case you selected the project node)
  2. Just the component that you selected (if changed, if it's up to date, Tortoise will tell you so)

Updating your Project/single Component is done by pressing the fifth button, which downloads the latest version from the repository and imports the component file(s) into your project.

Known Issues/Limitations

If a generic (shell called) version client shall be used, further entry dialogs (e.g. for entering the log messages) have to be added.

Points of Interest

  • The great version tool subversion and its cool Windows Explorer-based client tortoiseSVN, which I use now heavily for VBA source code versioning.
  • Also see Rob Bovey's site with the CodeCleaner addin (now also available as a COM component) that forms the basis for the source code saving.


  • 15/03/2007: Initial post to The Code Project
  • 09/04/2007
    • Bug fix: Loading now works for whole project
    • Enhancement: Added Stephen Bullens' VBEOnKey to enable shortcuts
  • 10/05/2007
    • Bug fix: Removed VBEOnKey again because of several severe side-effects (regular invocation of VBA code isn't too healthy...)
  • 04/04/2008: Added Usage section to the article


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Software Developer (Senior)
Austria Austria
No Biography provided

Comments and Discussions

BugSourceTools.xla does not work on Windows 10 Pin
Basil Hararah16-Jan-18 6:46
MemberBasil Hararah16-Jan-18 6:46 
QuestionIs this a bug for loading in excel 2007 Pin
nga9614-Oct-12 7:20
Membernga9614-Oct-12 7:20 
QuestionDoesn't load in Excel 2007? Pin
Aaron sher20-Jan-12 5:54
MemberAaron sher20-Jan-12 5:54 
AnswerRe: Doesn't load in Excel 2007? Pin
rkapl21-Jan-12 0:52
Memberrkapl21-Jan-12 0:52 
AnswerRe: Doesn't load in Excel 2007? Pin
NoelWatson6-Mar-12 22:54
MemberNoelWatson6-Mar-12 22:54 
AnswerRe: Doesn't load in Excel 2007? Pin
andresku19-Jun-12 22:50
Memberandresku19-Jun-12 22:50 
QuestionCould you explain more the difference of buttons 5 (Update) and 7 (Revert) to me who is unfamiliar with subversion? Pin
HerraTS28-Nov-11 12:21
MemberHerraTS28-Nov-11 12:21 
AnswerRe: Could you explain more the difference of buttons 5 (Update) and 7 (Revert) to me who is unfamiliar with subversion? Pin
rkapl21-Jan-12 0:50
Memberrkapl21-Jan-12 0:50 
QuestionIsn't there a bug with loading a whole project? Pin
Tim Davey27-Oct-10 0:45
MemberTim Davey27-Oct-10 0:45 
GeneralRe: Isn't there a bug with loading a whole project? Pin
Michael Ames24-Jul-12 4:57
MemberMichael Ames24-Jul-12 4:57 
AnswerRe: Isn't there a bug with loading a whole project? Pin
Member 937148522-Aug-12 3:49
MemberMember 937148522-Aug-12 3:49 
GeneralVersion controlling workbooks Pin
ginger_tosser25-Oct-10 21:51
Memberginger_tosser25-Oct-10 21:51 
GeneralMultiple addins Pin
Steve Towner18-Oct-10 8:38
MemberSteve Towner18-Oct-10 8:38 
GeneralExcel 2010 64-bit Pin
bonkey231-Aug-10 11:11
Memberbonkey231-Aug-10 11:11 
GeneralRe: Excel 2010 64-bit Pin
Steve Towner19-Oct-10 2:04
MemberSteve Towner19-Oct-10 2:04 
GeneralRe: Excel 2010 64-bit [modified] Pin
bonkey29-May-11 9:08
Memberbonkey29-May-11 9:08 
QuestionDoes it work with more than one machine on network? Pin
Daniel Bonetti18-Aug-10 9:40
MemberDaniel Bonetti18-Aug-10 9:40 
GeneralSourceTools for Mercurial Pin
ginger_tosser16-Apr-10 1:28
Memberginger_tosser16-Apr-10 1:28 
GeneralCommitting One Module and Overlay Icons question Pin
NYDean29-Sep-09 9:06
MemberNYDean29-Sep-09 9:06 
GeneralRe: Committing One Module and Overlay Icons question Pin
NYDean30-Sep-09 1:59
MemberNYDean30-Sep-09 1:59 
Generalvery cool Pin
bonkey220-Aug-09 7:48
Memberbonkey220-Aug-09 7:48 
QuestionUsing keyword expansion Pin
The Genius One14-Jun-09 12:14
MemberThe Genius One14-Jun-09 12:14 
AnswerRe: Using keyword expansion Pin
rkapl22-Jun-09 15:42
Memberrkapl22-Jun-09 15:42 
QuestionUpdates Pin
pablleaf8-Jun-09 4:35
Memberpablleaf8-Jun-09 4:35 
AnswerRe: Updates Pin
rkapl22-Jun-09 15:45
Memberrkapl22-Jun-09 15:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.