How to stop Excel from starting Worksheet_Change before Workbook_BeforeSave?

Update: Problem Solved My colleague changed the cell during Workbook_BeforeSave() without disabling events, so I ran Worksheet_Change() . Yes, silly, but at least it's our fault, not Excel

I noticed that whenever I press Ctrl + S in Excel, Worksheet_Change() gets run before Workbook_BeforeSave() . Is it possible to suppress this behavior using VBA code but not suppress all events (i.e. Without Application.EnableEvents = false )?

This happens no matter what I do. I read about someone with a similar problem with ComboBoxes, but I do not edit ComboBoxes, but Worksheet_Change() always fires before saving.

Any ideas? I'm just trying to figure out how to get around some code inside Worksheet_Change() when the document is saved, because this code should only be executed when the user actually changes something, and not while saving the book. Saving does not change in any case ...

+7
source share
2 answers

This was a mistake on our part:

My colleague changed the cell during Workbook_BeforeSave () without disabling events, so I ran Worksheet_Change ().

It was easy to fix. In Workbook_BeforeSave ():

 Application.EnableEvents = False ' Some final changes Application.EnableEvents = True 

And it was:)

+15
source

Add a global flag variable.

Enter the function that fires when the key is pressed, and if CTRL + S sets the flag to true.

The workheet_change event should be short if this flag is true.

And workbook_aftersave should change it to false.

+1
source

All Articles