For the VBA Code:
For code comparison purposes I'd suggest exporting the VBA module(s) and checking in the .bas
(regular module) and .cls
(class module) files and checking those in next to the .xlsm
.
Those exported VBA modules actually give you plain text versions of the code. Code in Worksheet / Workbook modules can also be exported as .cls
files. This will allow TortoiseHG to compare the actual code instead of the Excel file itself.
For the Excel file comparison on itself:
For comparing the actual XLSM, you can consider saving the file, changing the extension to .zip
and extracting the zips contents.
An Excel file for version 2007 and up is actually an archive containing XMLs that define the whole workbook and a .bin
file for the VBA Project.
You might want to pull said xmls through XMLLint or a similar tool, since they're not pretty printed by default.
Side note:
You're asking for a nice and smooth way - I'd say there is none within Excel itself. You can use VBA to do these Module Exports on Workbook_BeforeClose()
event, but you'll run into some security issues - By default you're not allowed to access the VBProject from within.
Of course there are some 3rd party tools for comparing VBA code without having to extract the modules, however "what to use" will be severely opinion based - BeyondCompare is indeed one option.
Hope this helps.