Vít Bednář
Vít Bednář

Reputation: 318

VSTO Word, Excel, PowerPoint detect Save and AutoSave

How to detect and distinguish in Office AddIn for Excel, Word, PowerPoint events for:

None of these three application have AfterSave, AfterAutoSave and AfterUiSave events.

Word and Excel dosen't have even DocumentClose event.

Upvotes: 1

Views: 127

Answers (1)

Vít Bednář
Vít Bednář

Reputation: 318

I solved almost all my problems, I would like to share my snippets.

Support for AfterSave, AfterAutoSave a AfterUiSave for Word I found here and used "as is": https://theofficecontext.com/2011/05/05/word-aftersave-event/

For Word document I registr for DocumentOpen this: ((Microsoft.Office.Interop.Word.DocumentEvents2_Event)document).Close += () => Document_Close(document);

Alteration PowerPoint I uploaded here: https://gist.github.com/VitekBed/fc2a24f67af3cf81784ba98f0bbc183f

Alteration for Excel also contains extension for WorkbookClosed (originally from https://gist.github.com/jmangelo/301884) uploaded here: https://gist.github.com/VitekBed/a2e1582ab9500e9513b39b85c53a6e89

Example from Excel ThisAddIn.cs, ThisAddIn.AppInit()

WorkbookClosedMonitor wcm = new WorkbookClosedMonitor(Application);
wcm.WorkbookClosed += new EventHandler<WorkbookClosedEventArgs>(wcm_WorkbookClosed);

WordSaveHandler wsh = new WordSaveHandler(Application);
wsh.AfterAutoSaveEvent += new WordSaveHandler.AfterSaveDelegate(wsh_AfterAutoSaveEvent);
wsh.AfterSaveEvent += new WordSaveHandler.AfterSaveDelegate(wsh_AfterSaveEvent);
wsh.AfterUiSaveEvent += new WordSaveHandler.AfterSaveDelegate(wsh_AfterUiSaveEvent);

Only unsolved problem is AfetrUiSave for PowerPoint, but it is not important use-case for me. For me is critical detect autosave and act different for save and autosave.

Upvotes: 1

Related Questions