Creating An Undo Handler To Undo Changes Done By Excel VBA

Introduction

This article uses techniques not available to Excel 97.

Unlike Word, changes made to an Excel workbook by using VBA cannot be undone easily. One has to write code that:

  • Stores the previous state of anything that (possibly) needs to be undone
  • Sets a sub to be run when the user selects undo
  • Write that subroutine, which reverses the changes last made by your code.

In this article I will demonstrate how one can use two class modules to create a (more or less) generic undo handler which one can plug into any project.

Contents

  1. Class Modules (1)
  2. Class Modules (2)
  3. Implementation
  4. Conclusion