jkramer
jkramer

Reputation: 91

Microsoft Word: Normal.dotm, cannot open the existing file: using Microsoft.Office.Interop.Word in c#

I have two printing process that uses Microsoft.Office.Interop.Word, and they will each run fine in isolated environments. However, when they are run one at a time on the same computer I get the Microsft Word error, "Word cannot open the existing file.(Normal.dotm)".

Our current solution to this problem is to delete the Normal.dotm template file between executions of the script(this works consistently), but we would like to not have to delete the template when it shouldn't be referenced or corrupted to our knowledge because opening a new document manually in Microsoft Word works fine.

The script that we run first creates and cleans up Word applications one at a time, and the second script creates a queue of Word applications that it uses to process large volumes of mail(note these processes are not overlapping in execution time). The error occurs when the second process creates its queue of applications. Both applications handle cleanup in the same fashion below...

wordApp.Application.Quit(false);
wordApp.Quit(false);
Marshal.FinalReleaseComObject(wordApp);
Thread.Sleep(1000);
GC.Collect(); 

Documents themselves are released as they are no longer needed as follows...

object noSave = Word.WdSaveOptions.wdDoNotSaveChanges;
doc.Close(ref noSave);
Marshal.FinalReleaseComObject(doc);

This is a relatively recent issue that started on our VNC's about five months ago. The error occurs on both Windows Server 2008 and 2012. We are using Microsft Word 2016. I have not encountered this issue in the past and any input would be appreciated.

Upvotes: 0

Views: 4051

Answers (1)

Oleg Onishchenko
Oleg Onishchenko

Reputation: 1

I solved the problem by setting ReadOnly on normal.dotm. Also remove write access rights of the user, under which Word is running. Tested for Word 2010.

Upvotes: 0

Related Questions