By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,873 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,873 IT Pros & Developers. It's quick & easy.

Word 2007 automation: problem with trapping save event

P: 1
I'm developing an addin for Word 2007 and I need to determine whether a user
saves a Word 2007 document in an older format (97-2003) after a save as is
done. The scenario is that the user starts out with a Word 2007 document,
saves that document to disk, then saves the same document in an older format

If the user saves a doc in an older format, I want to turn off certain
features of my add-in. I'm able to trap the save event easily enough and
provide the user with the Save as dialog and process the document type after
the save is completed. Here's a code snippet:

Expand|Select|Wrap|Line Numbers
  1. void _appClass_DocumentBeforeSave(Microsoft.Office.Interop.Word.Document 
  2. Doc, ref bool SaveAsUI, ref bool Cancel)
  3.         {
  4.  
  5.             if (SaveAsUI == true)
  6.             {
  7.                 string _origName = Doc.FullName;
  8.                 Cancel = true;
  9.                 object missing = Type.Missing;
  10.                 Word.Dialog fileSaveAsDlg = Application.Dialogs [Word.WdWordDialog.wdDialogFileSaveAs];
  11.                 fileSaveAsDlg.Show(ref missing);
  12.                 if (Doc.FullName != _origName)
  13.                 {
  14.                      ...do stuff
  15.                 }
  16.  
  17.              ... check document version type
  18.             }
  19.  
  20.         }
  21.  
  22.  
The problem is that Word 2007 supports save as dialogs for specific document
types but the only save as dialog I can produce above is a generic one that
defaults to the new file format. To produce a format-specific dialog, click
Word's Office button, then click Save As and you're presented with the option
of saving as a variety of document types.

If I take the approach above, I break this very helpful feature because even
though the user may have selecte to save as Word 97-2003 format, she still
gets the save as dialog defaulting to the Word 2007 format and has to
manually change it. However there is no way I've discovered to determine
which type of save as box the user intended and even if I could, I don't know
how to produce a save as dialog that matches the user's choice.

There also doesn't seem to be any post-save events so I can't process the
document type after the save event has completed. This seems to be a
deficiency in the Word 2007 object model.

Can anyone provide any guidance on a decent work-around for this? I want to
be able to fully support the Word 2007 functionality of being able to provide
the user with a document type-specific save as dialog while still being able
to trap the save event and process the document after the save (specifically
the save as) event has completed.

Thanks
Jan 7 '08 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.