title: VSTO Word post save event
body: <p>Sorry for the length of this, In the past I've been asked before to included everything I've tried when asking these sort of questions.</p>
  
  <p>I'm writing a Word Add-in and need to make changes to the document that I cannot achieve using the Word object model. Therefore, after the document is save to disk, I need to capture that event, close the file, do what I need to do and reopen it. (I know, not elegant, but that's what I have to work with.)</p>
  
  <p>Word has Before Save and Before Close, but no after save event. I found tricks online to simulate an after save event by creating another thread and using COM's <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms693740(v=vs.85).aspx" rel="nofollow">IMessageFilter</a> (not from System.Windows.Forms) to handle COM Retry calls, or posting a message back on the main thread so I can execute code after it's saved. But this doesn't work because if the file is saved as a result of the user attempting to close the document I can't get the file name in my "callback" method because Word.Document object has already been deleted. </p>
  
  <p>So I tried explicitly call Save myself in my BeforeSave event handler and return Cancel = true. That works great when user selects save, or they had once saved to disk. But if the user closes a new document without saving and then selects 'yes' to whether or not they want to save, Word displays another "SaveAs" dialog after I've already handled the save after I return from the BeforeSave event, even though I set Cancel = true in my BeforeSave event handler. </p>
  
  <p>So then I tried doing the something similar with the BeforeClose event. I handle the close and save myself and then returning Cancel = true from my event handler. But doing so stops word from trying to close multiple documents when the user is attempting to shut down the application. </p>
  
  <p>I even tried handling WM_CLOSE, but that lead to similar problems as above. </p>
  
  <p>Can anyone offer a solution?</p>