How to compare Visual Basic Modules in the Excel workbooks

If you are Excel developer, from time to time you need to compare old and new versions of your software. If you are working on the same workbook with your co-workers, version control is one of the important and complex tasks.

At first sight there is nothing complex. Excel offers you to export module into text file. So, you can export your macros into text files. Compare text files with text comparison software and import the files you need back into Excel application. If you are doing these actions on the daily basis, you are spending significant amount of time for this "intermediate" work.

Another important moment - VBA Code is not a plain text. It is set of declarations and sub\function definitions, and comparison tool should take this into account to produce accurate results. Usual text comparison tool which doesn't have Visual Basic specific it not always good.

Now, let's switch to xlCompare and see how it can help you. xlCompare does all the work itself and puts your attention into the comparison. As it compares Excel workbooks, it can't miss this important part - VB Project comparison.

xlCompare is not an Excel application. It doesn't have own Visual Basic Editor. But, this doesn't mean that you can't browse the VBA Modules in our software. In the Excel you should select menu\ribbon command to open VB Project or press Alt+F11. In the xlCompare you should use this button on the menu bar:

Now xlCompare switches to VB Project and displays all the VBA Modules, you have in the opened workbooks. You can browse code and switch between modules in the same way as you are working with worksheets. Now tabs display VB Modules and left and right pane display code:

In this example we've pressed the [...] button on the Tab bar to open list of all modules in the workbook. It works like a Combo Box control. This feature gives you quick and easy to use way to select modules.

We are using same interface features to compare worksheets and VBA Modules. This is our basis - tool should be as simple and easy to use as possible. Compare button and Compare | VBA Modules menu button starts the comparison. You can compare all modules in 2 workbooks and 2 different modules and same file.

Below is a result of the comparison. We've compared 2 Excel Add-ins (XLA file format) and made this screenshot.

Merge operations in the VBA Modules are also similar to the worksheet comparison. Every changed line in the VBA Code window has a checkbox. If you want to add this modification to the corresponding module - just check the line. To undo the operation - uncheck the box.

Every change is reflected in the Difference Browser window. On the image above Difference Browser is a small dialog with a tree control. Added and Deleted lines of code has checkbox which works in the same way as checkbox in the VBA Code Window. If you check it - line is added to another workbook. Changed lines has checboxes in the columns - Value 1 and Value 2, like a changed cells in the worksheet comparison.

So, you can see - you select workbooks and in one click you are getting results of the comparison. When you close xlCompare or close workbook xlCompare prompts you to save it, so you save your changed in a single click also!

Need Help?

If you have any problems with downloading please contact us.