none
Document with .doc set as template crashes Word RRS feed

  • Question

  • I have a client who is experiencing problems when opening documents in Word 2007 - Word shows a dialog "Microsoft Office Word has stopped working".  To be more specific, the documents are actually being accessed by a 3rd party document management system - the users do not have access to the underlying folders.

    The documents were originally created in Word 2003.  If the document is opened in Word 2003, or if the document is moved from its current location, the document opens correctly but it appears that the problem is to do with the template.  For example, if I open one of these documents on my local machine in Word 2007 it takes a few seconds to load, then appears to load correctly.  If I then click on the Developer tab on the Ribbon, click on the "Document Template" button the dialog appears but with this in the "Document Template" dialog box:

    \\Server1\partner\Docs\B\1\7\B1781\1\257645_1.doc

    This is the path to the document itself on my client's system - in other words, the document appears to be referencing itself as a template.  I assume that opening the document from my local machine works because the path doesn't exist on my network, so Word substitutes normal.dot or normal.dotm.

    There are hundred or possibly thousands of documents that cannot be readily accessed.  The client does not want to give users access to the folders directly, and has asked me to come up with a fix.

    Has anyone come across this kind of problem before and, if so, any ideas of how to fix it?

    Many thanks

    Edward

    Friday, September 9, 2011 8:16 AM

Answers

  • Hi Edward

    OK, I'm going to assume you know how to loop the files in a folder and won't post that code. I'll concentrate on the "open it in Word and change AttachedTemplate, save, close" part.

    using Word = Microsoft.Office.Interop.Word;
    
                object missing = System.Type.Missing;
                Word.Application wdApp = new Word.Application();
    //Loop
               //Substitute string with doc name
                string docName = @"C:\Test\Parts.docx";
                object oDocName = docName;
                object oFalse = false;
                //Opens the document so that it's not visible
                Word.Document Doc = wdApp.Documents.Open(ref oDocName, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref oFalse, ref missing,
                    ref missing, ref    missing, ref missing);
                //Following two lines are for info, only
                //Word.Template templ = (Word.Template) Doc.get_AttachedTemplate();
                //System.Diagnostics.Debug.Print(templ.FullName);
                object oTmpl = wdApp.NormalTemplate;
                Doc.set_AttachedTemplate(ref oTmpl);
                Doc.Save();
                Doc.Close(ref missing, ref missing, ref missing);
    //End Loop
    

     


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Liliane Teng Friday, September 16, 2011 10:59 AM
    Monday, September 12, 2011 9:13 AM
    Moderator

All replies

  • Hi Edward

    Strictly speaking, this is not a development issue. Unless you're need to change the code in the document management system in some way having to do with the Word object model?

    Otherwise, you need to ask this in a forum that supports Word from an end-user or IT perspective. I can move this to the IT forum for Word, if you think that would be the best venue.

    Straight end-user would be:
    http://answers.microsoft.com/en-us/office/forum/word


    Cindy Meister, VSTO/Word MVP
    Friday, September 9, 2011 8:38 AM
    Moderator
  • Hi Cindy

    I was aware that this might not be exactly the right forum for the question; it occurred to me that one possible fix for this might be to iterate over the documents and programmatically change the attached template.  However, I'm perfectly happy if you want to move this to a more suitable forum.

    Thanks

    Edward

    Friday, September 9, 2011 8:48 AM
  • Hi Edward

    Problem is, it's not certain whether doing that would solve the problem and what other issues it could cause (with that other software). And obviously, the best thing would be to correct whatever is causing this string to be added as the attached template - it's certainly not Word doing it.

    First thing I'd do is try changing that string (perferably on the client's configuration), save the document then re-open. That would tell you whether it helps and also, whether that software is going to change it back on you during the save/open process.


    Cindy Meister, VSTO/Word MVP
    Friday, September 9, 2011 9:52 AM
    Moderator
  • Hi Cindy

    My client (or the person with whom I'm liaising) tells me that he can open the document in Word 2003, change the template, save it and then the document is opened correctly both by Word 2007 and the third party software (which I understand is Partner Case Management).

    However, because of the sheer volume of documents, it's not feasible to open every one in Word2k3, manually change the template, save etc.

    Thoughts?

    Many thanks

    Edward

    Friday, September 9, 2011 11:03 AM
  • Hi Edward

    In this case, yes, looping through the documents in a folder, opening them and changing this would be a reasonable approach.

    Do you have a programming language preference?

    These are all *.doc files? That means we have no choice than to open them in the Word application...


    Cindy Meister, VSTO/Word MVP
    Friday, September 9, 2011 11:16 AM
    Moderator
  • Hi Cindy

    My language preference would be C#.

    Thanks

    Edward

    Friday, September 9, 2011 12:26 PM
  • Hi Edward

    OK, I'm going to assume you know how to loop the files in a folder and won't post that code. I'll concentrate on the "open it in Word and change AttachedTemplate, save, close" part.

    using Word = Microsoft.Office.Interop.Word;
    
                object missing = System.Type.Missing;
                Word.Application wdApp = new Word.Application();
    //Loop
               //Substitute string with doc name
                string docName = @"C:\Test\Parts.docx";
                object oDocName = docName;
                object oFalse = false;
                //Opens the document so that it's not visible
                Word.Document Doc = wdApp.Documents.Open(ref oDocName, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing,ref missing, ref missing, ref oFalse, ref missing,
                    ref missing, ref    missing, ref missing);
                //Following two lines are for info, only
                //Word.Template templ = (Word.Template) Doc.get_AttachedTemplate();
                //System.Diagnostics.Debug.Print(templ.FullName);
                object oTmpl = wdApp.NormalTemplate;
                Doc.set_AttachedTemplate(ref oTmpl);
                Doc.Save();
                Doc.Close(ref missing, ref missing, ref missing);
    //End Loop
    

     


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Liliane Teng Friday, September 16, 2011 10:59 AM
    Monday, September 12, 2011 9:13 AM
    Moderator