Prevent save in Calc with a macro

When a user clicks ‘save’ button, I need to do some validation in macro, if it’s invalid, then cannot save the document. How can I prevent saving using a macro?

Thanks in advance!

Hi,
I have the same question and I think the answer is insufficient.
It’s right that I can asign a macro to the event “onsave”, but I can’t prevent saving the document.

function onsave(oEvent as object)
oEvent.Source.disableSetModified()
onsave=false
end function

This prevent saving the document until you close the document.
Then appears the question “Document was modified. Save, discard or cancel?”
If you click “save” the document will be saved anyway.

Any ideas how to solve this problem?

In Menu/Tools/Customize/Events you can assign a macro to “Save document” event.