Whilst writing an add-in for office, I've had to define an eventhandler for the DocumentBeforeSave event.
This handler works fine except for one exception. This exception comes from the following:
save, don't save or cancel.don't save.Following these steps, office still forces me in the DocumentBeforeSave event. Without a way to determine if the user intended to cancel his save or not.
Is there a way to check if the user chose to save or not, and if so how? So far MSDN and other sources came up empty.
Note: In office 2013 and up, this should be checked by Doc.IsInAutosave, sadly this function doesn't exist in office 2007 and office 2010.
From what I assume based on your question you would like to run some piece of code only in the case that a document actually is saved.
A common solution to this is to intercept the actual Save command instead of registering an event handler for the DocumentBeforeSave event (which, as you describe, is also fired if the actual save operation never takes place).
How this is done is described in my answer here. Note that you would have to define the custom save command in your Ribbon XML, and then place the code that should run during save in the corresponding Ribbon callback function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With