top of page
  • John

Compare VBA Modules

Have you ever been in the situation where you have two versions of a Module and you want to know what is different (if anything) between the two?


Then the Compare Module command of VBE_Extras can help!


In the VBE's Project window, right-click on the Module that you want to compare 'from' and select 'Extras' > 'Compare Module'. Depending on the other Modules present in the same Project and depending on the Project(s) you have loaded in the VBE (and which host application you are using: not all host applications allow more than one Project to be loaded at a time), a dialog will display allowing you to select another Module to compare 'to':


  • Another Module of the same type in the same Project, or

  • Another Module of the same type in another Project, or

  • Another Module that has previously been saved as a file (e.g. using the VBE's built-in 'Export File' menu item or using VBE_Extras Version Control)


VBE_Extras will then perform the compare.


If no differences were identified then you will see ...


Dialog "Found no differences"

However, if differences were identified then you will first be shown an overview of the changes, such as ...


Differences summary dialog

... showing which members * have been added, deleted or modified. An individual member can then be selected and viewed:


  • If the member has been added then you can view the added code - that is, the code of the member in the Module that you right-clicked in the VBE (as the compare is 'from' that Module 'to' the subsequently selected Module)

  • If the member has been deleted then you can view the deleted code - that is, the code of the member in the subsequently selected Module (as the compare is 'to' that Module 'from' the Module that you initially right-clicked)

  • If the member has been modified then you can view the line-by-line and character-by-character differences highlighted:

    • Green - for insertions (will only appear in the upper text box representing the version of the text in the Module that you right-clicked ... that is, the Module being compared 'from')

    • Red - for deletions (will only appear in the lower text box representing the version of the text in the Module that you subsequently selected ... that is, the Module being compared 'to')

    • Yellow - for changes other than change of case ... i.e. a combination of a deletion and an insertion (so will appear in both the upper and lower text boxes)

    • Blue - for change of case only (so will appear in the upper and lower text boxes)


... like this:

Line-by-line differences dialog

Here you can see:

  • The text "item" has been changed to "ITEM" (a change of case only ... hence highlighted blue)

  • The text "Temporary text" has been changed to "Could not get the VBE's main menu" (a 'material' change ... hence highlighted yellow)

  • The line ".Visible = True" has been deleted i.e. it is only present in the version of the Module that is being compared 'to' but is not present in the version of the Module that is being compared 'from' (hence highlighted red and, obviously, only visible in the lower text box representing the compared 'to' version)

  • The line starting "Set mcmdBarButtonBackup = ..." has been added i.e. it is present in the version of the Module that is being compared 'from' but it is not present in the version of the Module that is being compared 'to' (hence highlighted green and, obviously, only visible in the upper text box representing the compared 'from' version)


* The breakdown of 'Module members' is by individual procedure and property plus as groups of lines (in other words, each of these is treated as though they were an individual member in their own right and will have insertions, deletions and changes reported in the same way):


  • All Module declaration lines

  • All Module-level VBA Attributes

  • For Access Forms and Reports, all 'control and UI layout' lines


Anything else?


As well as the Compare Module command, VBE_Extras also includes a Compare Project command. This performs a compare of each Module within a Project to those in another Project - either another Project loaded in the VBE or a Project that has been previously saved to the file system (there's no built-in way to export an entire Project using the VBE ... but you can do it using VBE_Extras Version Control command).


Compare Project additionally compares the Project's 'Project References' and identifies those that have been added or removed or have changed in priority (not sure what 'Project References' are ... or want a better way to add / remove them ... then read my Adding / updating "Project References" in the VBE post).


And for host applications that support "embedded" RibbonX customisations of the ribbon (i.e. Excel, Word and PowerPoint ... not Access or Outlook) then the Project's RibbonX will also be compared to identify any changes and display them to you in the same dialogs (with the same highlight colours) as above for Module members.


Recent Posts

See All

Comments


bottom of page