Word AfterSave event?

Add-in Express™ Support Service
That's what is more important than anything else

Word AfterSave event?
 
Omri Suissa


Guest


Hi,
I need to get notified after word saved a document.
I tried this solution: http://www.add-in-express.com/forum/read.php?PAGEN_1=1&FID=5&TID=4539
but i keep getting exceptions even after the save is complete (word 2010).

can you help me?

Omri
Posted 14 Nov, 2011 08:50:23 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Omri,

Does the code compile for you?

Who will be the initiator of the save in your case: Word, the user, or both?


Andrei Smolin
Add-in Express Team Leader
Posted 14 Nov, 2011 09:04:05 Top
Omri Suissa


Guest


Hi,
I'm using c# so i wrote the code myself.
the initiator of the save is the user.

Omri
Posted 14 Nov, 2011 09:06:07 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
In this case, you can override all the controls and keyboard shortcuts initiating the save operation and implement all the logic in your code: show the FileSave dialog (if required), call Document.Save, handle exceptions and, finally, generate the "document is saved" notification.


Andrei Smolin
Add-in Express Team Leader
Posted 14 Nov, 2011 09:35:24 Top
Omri Suissa


Guest


This is not a practical solution.
I can't and won't map all the logic of save in word (sounds very unstable).
Do you know why the original solution is not working in my case?
Posted 14 Nov, 2011 09:41:34 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
What do you mean by "mapping the logic of save"?

Once again:
- you connect to built-in controls in the Word UI: this possibility exists both in the CommandBar and Ribbon UI;
- you don't let the built-in controls invoke the corresponding Word functionality: this is absolutely legal, too, the Click event for both CommandBar and Ribbon UI buttons has the Cancel parameter;
- you invoke your functionality instead: this is what intercepting built-in controls is purposed for - invoking your code instead of the built-in functionality.

Omri Suissa writes:
Do you know why the original solution is not working in my case?


No, I don't. Morover, that solution isn't ours; we cannot support it.


Andrei Smolin
Add-in Express Team Leader
Posted 14 Nov, 2011 10:15:21 Top
Omri Suissa


Guest


Yes, but this is a "brutal" option. what if another addon is installed and act the same? one of the addons wont work...
I always prefer an none-intrusive design to ensure stability in unknown environments.
Posted 15 Nov, 2011 01:15:25 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Omri Suissa writes:
one of the addons wont work...


Why? Will it be an exception? Or one of them will not be called? I don't understand...

Theoretically, there are two approaches:
- either invoke the Save in your code so that the next operator will mean "after save"
- or check the state of the document now and then

In the second approach, there's a chance that the user or another add-in will perform some action just between 'now' and 'then'. Or, there's a possibility that 'then' will never occur, e.g. the document will be closed.


Andrei Smolin
Add-in Express Team Leader
Posted 15 Nov, 2011 02:43:13 Top
Omri Suissa


Guest


Hi,
yes you are right, but when i'm implementing my own save (open the file dialog and everything) i need to cancel the event so word will not open its own save dialog for example.
In this case other addons will also be called? (what happen if they do the same? another dialog will be open? the other addon will not be called?)
Posted 15 Nov, 2011 09:23:38 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
You need to intercept the DocumentBeforeSave event of the Word.Application object. In Add-in Express you find this event in the Word Events component. You'll need to set the SaveAsUI parameter to false.


Andrei Smolin
Add-in Express Team Leader
Posted 15 Nov, 2011 09:38:23 Top