top of page

Restore points for VBA code

  • Writer: John
    John
  • Apr 15
  • 3 min read

Wouldn't it be great if the Visual Basic Editor (the VBE) had the ability to create 'restore points' so that if you change your VBA code in a way that you subsequently decide that you wished you hadn't done, then you could just restore it back to an earlier point with a few mouse clicks?


I think it would be great ... and I think it would 'save the day' on many occasions. In fact, I think it would be so great that I decided to add 'restore points' functionality to VBE_Extras.


Restore points mean that you can store, and subsequently restore:

  • Your VBA code

  • Attributes associated with your VBA code

  • User-interface elements of UserForms

  • In MS Access, user-interface elements of Forms and Reports


… this includes adding any Modules that you deleted since the restore point was created, and deleting any Modules that you added since the restore point was created (but see Document Modules in host applications other than Access, below) … restore points are like a limited form of Version Control ... limited because:


  • They do not include everything that Version Control does (they do not include Project References and RibbonX code)

  • They are 'temporary' ... while an export created using Version Control will exist until you delete it, the idea of restore points is that they are temporary allowing you to rectify something in your code a short while after you made a change (or after you asked VBE_Extras to make a change via a refactoring command) ... just how temporary they are is controlled via the 'Restore points' tab of the Settings


You can create a restore point at any time ... do so via the menu: Extras > Backup and Restore > Create restore point.


Additionally, restore points are automatically created prior to running VBE_Extras refactoring commands (for example, prior to renaming, adding/removing/re-ordering parameters and indenting your code). Note that there are various options (in the VBE_Extras Settings, tab 'Restore points') controlling when restore points are automatically created. You may want to ensure these options are set just as you would want them.


Settings for restore points

Restoring is done via the menu: Extras > Backup and restore > Restore. You will be asked to select the desired restore point (if multiple have been created) and then you will always first be shown a 'diff report' before any restore takes place. This gives you the opportunity to review the details of exactly what will be changed by restoring (down to the character level ... see example screenshot below) and then you can decide either to proceed with the restore or not.


For more information on the 'diff report', see sections of the Version Control post relating to diff reports (that is, sections 'Project-level diff report', 'Module-level diff report' and 'Member-level diff report').


Member-level diff report

Document Modules in host applications other than Access

In Access, Document Modules (i.e. Forms and Reports) can be added and removed (and their code restored) the same as with any other type of Module.


In all other host applications (Excel, Word, PowerPoint and Outlook), Document Modules cannot be added or removed as the VBE does not support this (for example, in Excel, Worksheets cannot be added or removed using the VBE ... this must happen in the Excel user-interface).


As such, a restore can only replace (or remove) code in existing Document Module(s).


See the VBE_Extras user guide section 'Document Modules in host applications other than Access' for more details.


More information on restoring and restore points


See the VBE_Extras user guide, sections 'Create restore point' and 'Restore'.

Comments


bottom of page