Home > Posts > Prevent new Word application from using existing instance

Prevent new Word application from using existing instance

// Workaround to prevent manually started instances of Word from hijacking automation process.
// BUG: Starting Word Manually Uses Same Instance as Automation
// http://support.microsoft.com/kb/188546/EN-US/
// Article ID : 188546
// Last Review : January 23, 2007
// Revision : 3.3

void WordServer_DocumentChange() {
    try {
      object objSaveChanges = WdSaveOptions.wdDoNotSaveChanges;
      object objMissing = Missing.Value;
      m_App.ActiveDocument.Close(ref objSaveChanges , ref objMissing , ref objMissing);
    }
    catch (System.Runtime.InteropServices.COMException ex){
       MessageBox.Show(string.Format("Error: {0} ({1})", ex.Message, ex.ErrorCode));
    }
}

for more info see this discussion at the old MSDN forums (btw, these forums are under transition to the new MSDN forums)

Advertisements
Categories: Posts
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: