Excel Goodies
SourceTools

Introduction

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 add-in, which was abused as a “SourceStripper” here.

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

  • The first button (or Ctrl+Shift+O) 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:

  • The second button (or Ctrl+Shift+S) is used to save a project or a selected component of a project (common module, class module or userform).
  • 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 (or Ctrl+Shift+D) 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 (or Ctrl+Shift+U) updates the whole project or selected component from the repository, notifying any conflicts.
  • The sixth button (or Ctrl+Shift+C) commits the whole project or selected component to the repository, asking for a log message before.
  • Finally the seventh (or Ctrl+Shift+R) 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 done by simply copying SourceTools.xla into your XLStart folder. You also have to enable access to VB project in menu Tools/ Macro/ Security, tab "Trusted Sources", checkbox "Trust access to Visual Basic Project".

Configuration is done in module MGlobals using mainly the following 6 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.

To change the shortcut keys, modify procedure "AddMenuItems" in Class Module "CMenuHandler":

  VBEOnKey "+^S", ThisWorkbook.Name & "!SaveTo"
VBEOnKey "+^O", ThisWorkbook.Name & "!LoadFrom"
VBEOnKey "+^D", ThisWorkbook.Name & "!Diff"
VBEOnKey "+^C", ThisWorkbook.Name & "!Commit"
VBEOnKey "+^U", ThisWorkbook.Name & "!Update"
VBEOnKey "+^R", ThisWorkbook.Name & "!Revert"

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 also for VBA sourcecode 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. Also see Stephen Bullens OfficeAtomation's site and his VBEOnKey module that enable adding shortcut keys in the VBE.

History

  • 15/03/2007: Initial post to Codeproject.
  • 09/04/2007: 
    • Bugfixes: Loading now works for whole project.
    • Enhancement: Added Stephen Bullens VBEOnKey to enable shortcuts.