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   
QuestionIs this a bug for loading in excel 2007membernga9614 Oct '12 - 7:20 
My computer is win7(32 bit) + excel 2007.
 
This is the exact tool I am looking for. It can export all VBA codes from excel. However, when I import vba codes back to excel VBA projects. It always fail.
 
I reviewed the codes. In the Load() function, there is such statements:
' save ourselves from restoring ...
If InStr(1, wbPath, "SourceTools.xla") > 0 Then Exit Sub
 
Since wbPath has been assigned a string, so we always exit sub. then load project will fail.
 
Is there anyone encounter the same issue?
QuestionDoesn't load in Excel 2007?memberAaron sher20 Jan '12 - 5:54 
As far as I can tell, I've followed the instructions correctly (though since they're written for a pre-Ribbon version it's pretty difficult to map them to Microsoft's genius new UI), but nothing shows up. I don't have a Source toolbar in the VBA interface. Any suggestions?
 
Aaron
AnswerRe: Doesn't load in Excel 2007?memberrkapl21 Jan '12 - 0:52 
Sorry I dont have Excel 2007 yet, but it could be due to 64Bit Problems (See below)
AnswerRe: Doesn't load in Excel 2007?memberNoelWatson6 Mar '12 - 22:54 
Aaron, did you get this working?
AnswerRe: Doesn't load in Excel 2007?memberandresku19 Jun '12 - 22:50 
Hi Aaron,
 
i have the same problem. Have you resolved the issue? How was the solution?
 
Thank you for the note.
 
Andreas
QuestionCould you explain more the difference of buttons 5 (Update) and 7 (Revert) to me who is unfamiliar with subversion?memberHerraTS28 Nov '11 - 12:21 
Hi,
Thanks for the helpful tool. I've recently started the use and am making great versions.
However, now that I've had the need of restoring VBA of latest version to Excel file previous version due to file corruption I would need to understand the Update and Revert features more.
 
If I replace the Excel file from SVN to last working version, then I need to add the latest VBA.
I know the modules that have changed (a from).
If I click the module and click 5 (Update), I would not see changes to code in VBE.
But after looking around the files in .src-folder have changed.
How do I get the updated files also to VBE again?
 
I have not dared to try test the 7 (Revert) due to this previous experience.
Can you explain the difference here: what is updated & where?
BR, Tomi

AnswerRe: Could you explain more the difference of buttons 5 (Update) and 7 (Revert) to me who is unfamiliar with subversion?memberrkapl21 Jan '12 - 0:50 
Revert is for reverting to a previous Version (what you probably want), update is for getting the latest (Head) Version from the repositiry. Usually you Update in a Multi Developer context to get the others latest Development work.
QuestionIsn't there a bug with loading a whole project?memberTim Davey27 Oct '10 - 0:45 
Does everyone find loading a whole project works? For me it deletes all the VBA and doesn't import from the saved directory. It would seem strange that only I am finding this - but I have found by singlestepping the code what appears to be a bug. When selecting the directory to load from, it will end in ".src". This is passed in the code to the variable wbPath in LoadFrom(), but ImportFiles2() appends the ".src" a second time, so the directory is not found and the load fails. This is easily fixed by removing "& FolderExtension" in 3 places.
 
But why is it just me? Am I missing something?
 
I am using Vista / Excel 2007
 
Tim
GeneralRe: Isn't there a bug with loading a whole project?memberMichael Ames24 Jul '12 - 4:57 
Thank you very much for this hint! I removed the three "FolderExtension" in ImportFiles2() and now loading the complete project does work on my machine (WIN7 / Office 2007)
 
Michael
AnswerRe: Isn't there a bug with loading a whole project?memberMember 937148522 Aug '12 - 3:49 
Thanks a lot for the hint! Had the same issues with Excel 2003.
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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 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