Click here to Skip to main content
Click here to Skip to main content

SourceTools.xla

By , 5 Apr 2008
 

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 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.

Usage

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 Sourceforge.net 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.

History

  • 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

License

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

About the Author

rkapl
Software Developer (Senior) Austrian Federal Financing Agency
Austria Austria
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralVersion controlling workbooksmemberginger_tosser25 Oct '10 - 21:51 
Roland,
 
I'm having trouble getting sourcetools.xla to version workbooks, specifically "ThisWorkbook.xwk". Is this feature supported or am I doing something wrong?
Also, given the fact that this is a tool for version controlling some code, how about releasing the code into an online SVN repository so that we can all contribute and improve it (how is OTSVN coming along?)
 
M
GeneralMultiple addinsmemberSteve Towner18 Oct '10 - 8:38 
Anyone played around with multiple add-ins? I have three add-ins that I would like to control separately. As the .xla files are all in the same folder, this does not seem to be possible. Anyone found this problem, or a work around?
 
Thanks,
 
Steve
GeneralExcel 2010 64-bitmemberbonkey231 Aug '10 - 11:11 
I am an experienced user of this tool in excel 2003. I have upgraded to excel 2010 64-bit and am trying to get this to work in the new version. This is on Windows 7 64-bit.
 
The first thing it complains on compile about the Private Declare Function lines, it made me change them to Private Declare PtrSafe Function. I made the change, and it compiles now.
 
When I open a excel project and enter VBA, I see the menu as expected. However, when I press the buttons nothing happens. My guess is that the hooks are not working properly.
 
I can run the code manually to save or commit and it seems to work okay, just not the buttons.
 
Any ideas on how to update this to work with 64-bit 2010?
GeneralRe: Excel 2010 64-bitmemberSteve Towner19 Oct '10 - 2:04 
I am using 2010 with Win 7 x64 and I have no problems. Did not need to change anything, so I think it maybe your machine, not the tool.
GeneralRe: Excel 2010 64-bit [modified]memberbonkey29 May '11 - 9:08 
Are you running .xls or .xlsm ?
 

I get this message when I open excel with SourceTools.xla in place.
 

Compile error:
 
The code in this project must be updated for use on 64-bit systems.
Please review and update Declare statements and then mark them with
the PtrSafe attribute.
 

 
If I make the changes then I can run the macros manually, but the buttons don't work.
modified on Monday, May 9, 2011 4:50 PM

QuestionDoes it work with more than one machine on network?memberDaniel Bonetti18 Aug '10 - 9:40 
Hi,
 
That add-in works very well for me when using it only in my PC.
 
I've tried to make it to work in two (or more) machines. So, when I change only one Form (on Machine 1), I have to commit all others FRX files (I have almost 150 Forms). So far so good. When I perform an Update on Machine 2 I get conflicts with all FRX files. Since then, I need to open Windows Explorer and to solve the conflict.
 
Does the add-in work with more than one machine on network? Or does anyone know how to solve that? I've been tried to put the VBA source under a control version the more than 2 months!
 
Thank you very much!
 
Daniel
GeneralSourceTools for Mercurialmemberginger_tosser16 Apr '10 - 1:28 
Hi, I love this tool, it makes managing an excel vba project with SVN much easier. I am now starting to use Mercurial (aka Hg) and TortoiseHg and have modified SourceTools to call hgtk.exe. At present it just replicates the original 5 buttons so there is no distributed funcionality in there yet (shelve, push, pull etc).
 
Assuming rkapl is happy with this, where would the majority prefer to see it hosted - I'm guessing bitbucket since that is where TortoiseHg lives but I'll leave it open to debate for a while and see who wins.
GeneralCommitting One Module and Overlay Icons questionmemberNYDean29 Sep '09 - 9:06 
This seems to be a small, very minor issue, but as I am just now testing this tool, it seems that if one module has a small change made to it, when I go to commit just that one module to the repository, I am told by the Tortoise UI that "No files were changed or added since the last commit....". If however, I go to commit all the modules, then it notices that that one module was indeed changed.... curious. Have you noticed that as well?
 
Also, I'm a bit confused about the Overlay Icons in Windows explorer. I followed your setup steps exactly. And after importing the .XLS file along with the .XLS.SRC folder, and then subsequently checking them out to an empty folder, only the .XLS.SRC folder has the expected Overlay Icon. And as I continue to modify that .XLS and its modules the Overaly Icon does not appear on the file but does appear on the .XLS.SRC folder. Do you have any idea why the .XLS file does not have that Overlay Icon? Have I possibly done something incorrect?
 
This is a Windows XP Pro SP3 machine with Subversion setup on a server and TortoiseSVN installed on the workstation.
GeneralRe: Committing One Module and Overlay Icons questionmemberNYDean30 Sep '09 - 1:59 
At least as far as the Overlay Icons issue goes... that was easily remedied by changing the TortoiseSVN Settings and putting a checkmark by Network Drives. I'm still not sure why the folder had the right icons and the workbook did not, but in any case, that took care of that issue.
Generalvery coolmemberbonkey220 Aug '09 - 7:48 
Just wanted to say this did everything I wanted, and more. Thanks.
QuestionUsing keyword expansionmemberThe Genius One14 Jun '09 - 12:14 
Hello,
 
does anybody know how I can get keywords expanded in my VBA-modules?
 
I setup keyword expansion for *.bas within TSVN.
This causes expansion in the files SourceTool handles.
e.g. TestWorkbook.xls.src\Modul1.bas contains expanded keywords.
 
'$LastChangedDate: 2009-06-15 00:09:01 +0200 (Mo, 15 Jun 2009) $
'$Rev: 8 $
 
But in VB-editor I don't get the expanded keywords. Only the keywords themself.
'$LastChangedDate$
'$Rev$
 
Thanks for any reply!!
AnswerRe: Using keyword expansionmemberrkapl22 Jun '09 - 15:42 
Hi!
 
This is due to the fact that you have to reimport the Modules. Either you can do this manually by "opening" the files with the first button or it is done automatically when updating the files from the repository.
 
The source files on disk are just exported modules, when importing them again into Excel, the modules should contain everything that was changed outside (except module meta information, such as Attribute VB_.. entries and the like.
 
-regards,
Roland
QuestionUpdatesmemberpablleaf8 Jun '09 - 4:35 
This is a great tool and it has been a life saver!
 
I just wanted to let you know that i have taken the liberty to add some new buttons to your toolbar. the revision graph and repobrowser!
 

AnswerRe: Updatesmemberrkapl22 Jun '09 - 15:45 
good to hear that. I collect these ideas for the successor tool "OTSVN" (whenever I find the time to finish it).
 
-regards,
Roland

Question.frx filesmemberMember 578656922 Jan '09 - 6:02 
This is definitely one of the most creative and helpful tools I've found in a long time. I noticed, though, that every time I perform a commit or diff, any .frx files show up as having changed, even if I haven't changed them (or made any changes to the entire file at all). Do you have any ideas how to fix this?
 
Zach
AnswerRe: .frx filesmemberrkapl22 Jan '09 - 10:35 
Sorry, there's no way to fix this as it is VBA behaviour to change a few bytes every time you export a userform to a frx (binary data in the form) file.
 
But as the frx file is binary anyway and therefore useless for source control, I tend to ignore it (however still put it under source control, as there are still sometimes changes to it).
 
-sorry, but that's it.
Roland
QuestionIs there a tutorial that explain the usage in more details?memberkaifu12 Jan '09 - 9:35 
From what I have seen while working with this code, this code will be a tremendous help in updating my excel spreasheets. However, I still couldn't figure out how to compare my existing spreadsheets and the previous versions. Help! please!
AnswerRe: Is there a tutorial that explain the usage in more details?memberrkapl13 Jan '09 - 10:35 
Hi kaifu!
 
Thanks for the nice words, however I have to make one thing clear: Sourcetool.xla is NOT for comparing Spreadsheets, rather for comparing the VBA code modules inside Excel Workbooks.
 
After having said that, the following procedure can be used to compare different versions of code modules.
 
Go to the .xls.src folder that was created during the initial save of the code module and put under version control using Tortoise SVN as described. Using the Tortoise SVN (version 1.5.3 and above) context menu of that folder, use "Show Log" to display all versions of the repository.
 
You can then use the topmost part of the log messages window to compare either the various versions with the working copy in your local checkout folder (context menu "compare with working copy") or with the respective previous version (context menu "compare with previous version").
 
-regards,
Roland

QuestionDoes any one know if there is a way to change VBIDE.VBComponent icons in VBE? [modified]memberStevenLi17 Oct '08 - 11:24 
It will be very nice so that you see the svn source control status right in VBE without going to Windows Explorer.
 
Also inspired by Rob Bovey's CodeCleaner, I implemented an also identical program (functionality-wise) for SourceSafe using its API, but since has been looking for a way to override the icons...
 
Thanks,
 
Steven
 
modified on Friday, October 17, 2008 5:49 PM

AnswerRe: Does any one know if there is a way to change VBIDE.VBComponent icons in VBE?memberStevenLi29 Oct '08 - 2:36 
After some research I found some more information regarding this:
 
Tortoise SVN has a project dedicated to icons at here: TortoiseOverlays it utilizes windows shell's internal support for icon overlays as well as windows registry to achieve this.
 
Through a combination of windows control API (comctl32.dll) calls (TreeView_GetImageList, ImageList_AddIcon, and ImageList_SetOverlayImage), I was able to overlay an icon image on top of a tree node within the project explorer treeview control.
GeneralRe: Does any one know if there is a way to change VBIDE.VBComponent icons in VBE?memberrkapl29 Oct '08 - 14:05 
Dear Steven!
 
Great! Would love to hear more about that, as I'm also trying to make the new subversion addin (also for other office VBA parts, Word, powerpoint, access...) a bit more slick.
 
-regards,
Roland
GeneralRe: Does any one know if there is a way to change VBIDE.VBComponent icons in VBE?memberGISHY774 Nov '11 - 11:14 
Can you show how you did this?
QuestionButtons don't workmemberSebastian Paul8 Sep '08 - 23:47 
Hi, I set breakpoints to each SUB in MExportImport
when i click Save the code is never executed
 
when i manually start "saveto()" your code exports MExportImport, nothing more.
 
I set up the paths and the "security setting", do i need something else?
AnswerRe: Buttons don't workmemberrkapl9 Sep '08 - 19:41 
Well, which Office version/part of Office are you using it in?
 
-regards,
Roland
GeneralRe: Buttons don't workmemberSebastian Paul9 Sep '08 - 23:37 
I'm using Excel 2003,
but now save works,
don't know why, just reinstalled your code one more time and changed nothing in the settings.
 
tried this several times before and did not work...
 
now going to test everything else..
 
just one last short question,
 
your tool also exports the workbooks als .xwk files.
since my code is jusst in a xla and not inside a workbook, can i turn this off?

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

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 5 Apr 2008
Article Copyright 2007 by rkapl
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid