Excel VBA Workbook EventsThe Complete Automation Series

Excel VBA workbook events: Workbook_Open, BeforeClose, Worksheet_Change automation macros

Button macros wait for someone to press the button. Workbook events run themselves. This is the complete FinDataPro VBA series: 20 dedicated guides, each targeting one event or method, every snippet finance-tested and copy-paste ready.

14 June 2026Series hub
Prashant Panchal
Prashant Panchal

ACA | FMVA® | 19 Years in Finance

The moment a workbook opens, Excel fires Workbook_Open. A cell changes, it fires Worksheet_Change. The workbook is about to close, it fires Workbook_BeforeClose. You write the code once in the correct module and it executes automatically, for every user, every time.

In finance, this is not a productivity trick. It is infrastructure. Shared workbooks (month-end close files, budget trackers, reconciliation templates, journal entry logs) fail at the human steps, not the accounting. Someone forgets to re-apply sheet protection. Unsaved changes vanish when a colleague clicks "Don't Save." A macro breaks because the bank statement CSV was moved to a different folder. Event-driven VBA removes those failure points entirely.

This series covers twenty topics across three tiers. Every snippet is tested, finance-specific, and written for accountants who need to understand the code, not just copy it.

A Quick Example: Workbook_Open

Paste this into the ThisWorkbook module (Alt + F11, then double-click ThisWorkbook under Microsoft Excel Objects). It unprotects a named sheet every time the file opens:

Option Explicit

Private Sub Workbook_Open()
    ' Unprotect the data entry sheet on open
    ' Combine with Workbook_BeforeClose to re-protect on close
    Dim wsData As Worksheet
    Set wsData = ThisWorkbook.Sheets("Data Entry")
    wsData.Unprotect Password:="YourPasswordHere"
End Sub

Combine it with the Workbook_BeforeClose guide to re-apply protection on close. That is the standard protect-and-unprotect pattern for shared finance workbooks.

Where Does the Code Go?

The single most common mistake in event-procedure setups: pasting code into the wrong module. Workbook_Open and Workbook_BeforeClose belong in ThisWorkbook. Worksheet_Change belongs in the module for the specific sheet you want to monitor. Standard modules (Module1, Module2) are for subs you call manually. An event procedure pasted into Module1 will never fire, with no error and no warning.

How to navigate to the right module

  1. Open the VBA Editor: Alt + F11
  2. In the Project window (top-left), expand your workbook name
  3. Expand Microsoft Excel Objects
  4. Double-click ThisWorkbook for workbook-level events
  5. Double-click the sheet name (e.g. Sheet1) for worksheet-level events

Basic Tier: Events and Methods

Start here if you are new to event-driven VBA. These eleven guides cover the core events and methods used daily in finance workbooks: open, close, cell-change, new workbooks, and file selection.

Intermediate Tier: Patterns and Performance

Once you are comfortable with the basic event model, move to these. They cover the techniques that matter when workbooks grow: looping through folders, proper error handling with On Error GoTo, and the performance gap between Range and array operations on large datasets.

Advanced Tier: Automation Beyond the Worksheet

These four go past the worksheet entirely: deduplicating with a Dictionary object, exporting individual PDFs, sending email straight from Outlook, and building a proper UserForm for non-technical staff.

Frequently Asked Questions

Where does the VBA code for workbook events go?

Workbook-level events (Workbook_Open, Workbook_BeforeClose) go in the ThisWorkbook module. Worksheet-level events (Worksheet_Change) go in the specific sheet's module. Standard modules are for manually triggered subs. An event procedure pasted into a standard module will never fire.

What is the difference between a workbook event and a worksheet event?

A workbook event fires on actions affecting the workbook as a whole: opening, closing, saving. A worksheet event fires on actions affecting a specific sheet: a cell changing, the sheet being activated. Workbook events go in ThisWorkbook; worksheet events go in the individual sheet module.

Do workbook events work in Excel for Mac?

Yes. Workbook_Open, Workbook_BeforeClose, and Worksheet_Change all work in Excel for Mac with .xlsm files. Application.GetOpenFilename works on Mac but file filter syntax differs. Test before distributing to Mac users.

Do I need to save as .xlsm for events to work?

Yes. Saving as .xlsx strips all VBA code silently. Excel warns you before doing so. Save as .xlsm (macro-enabled) or .xlsb (binary) to preserve event procedures. Even with the correct format, if a user's Trust Center blocks macros, no events will fire.

For the full VBA event reference, see the Microsoft Learn VBA Workbook Events reference.

Discussion

Leave a Comment

0/2000

Comments are moderated and appear once approved.

Prashant Panchal
Prashant Panchal• ACA | FMVA® | 19 Years in Finance

Prashant Panchal is a Chartered Accountant (ACA) and Financial Modelling & Valuation Analyst (FMVA®) with 19 years of experience in finance, FP&A, and financial modelling across the GCC region. He is the founder of FinDataPro.