none
How to disable template checking programmatically when opening a WORD document? RRS feed

  • Question

  • When using Microsoft.Office.Interop.Word lib to open a word document, it would be very slow for some documents to be opened. It seems it's contacting some server for some template, it's easy to just disable in the menu option in word. But now we need to do it in our program, it seems no way to disable the template checking and speed up the opening process.

    I've tried to set word document's AttachedTemplate property to null or something like "C:\Users\xxx\AppData\Roaming\Microsoft\Templates\Normal.dotm", but it didn't work well. The doc couldn't even be opened that way.

    Is there any way to make it work? Thanks.

    Thursday, January 25, 2018 7:29 AM

Answers

  • Hi mspeninsula

    Some infos you might or might not find useful:

    I faced the same problem in the past when creating a small macro which processed a list of Word documents. Some of them opened very slowly because they were linked to the template files used when they were created. However, these templates were located on a file server that did not exist anymore. When opening, each document tried to access the file server and Word was "locked" until a timeout occurred. Guess at the time we used Word 2010.

    As only a hand-full of users had to run the macro (and only for a limited time), I advised them to have everything required for the macro to run saved locally on their machine and then unplug the network cable before starting the macro. Without network connection, Word did not try to connect to the template server (or at least the timeout occurred much faster).

    Most probably is no approach in your situation...

    But is should be possible to re-assign an existing document to the local Normal.dotm template by assigning an empty string to the AttachedTemplate property:

    ActiveDocument.AttachedTemplate=""

    Of course that would mean you have to pre-process the documents used by your application first (which still will be slow). But afterwards the documents should open up just fine.

    Luca

    • Proposed as answer by Terry Xu - MSFT Monday, February 5, 2018 9:03 AM
    • Marked as answer by mspeninsula Tuesday, February 6, 2018 3:06 AM
    Friday, February 2, 2018 11:14 AM

All replies

  • Hello mspeninsula,

     >>it would be very slow for some documents to be opened,It seems it's contacting some server for some template

    Are you sure it is caused by template? If you open the document manually, will it be very solw?I would suggest you back up the templates and create empty templat as replacement for testing if it is caused by the template. 

    Best Regards,

    Terry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 26, 2018 10:22 AM
  • Yes, it's also slow if I manually open it, that's why I figured out it was caused by the template.  

    It was contacting a server for template, I think the network connecting is slow, but I don't have the permission to change the document. I'm processing a lot of docs and need to improve the efficiency without changing the documents themselves. So I was wondering if there was anyway I can bypass it or just disable it in my code?

    Friday, January 26, 2018 1:07 PM
  • Hi mspeninsula

    Some infos you might or might not find useful:

    I faced the same problem in the past when creating a small macro which processed a list of Word documents. Some of them opened very slowly because they were linked to the template files used when they were created. However, these templates were located on a file server that did not exist anymore. When opening, each document tried to access the file server and Word was "locked" until a timeout occurred. Guess at the time we used Word 2010.

    As only a hand-full of users had to run the macro (and only for a limited time), I advised them to have everything required for the macro to run saved locally on their machine and then unplug the network cable before starting the macro. Without network connection, Word did not try to connect to the template server (or at least the timeout occurred much faster).

    Most probably is no approach in your situation...

    But is should be possible to re-assign an existing document to the local Normal.dotm template by assigning an empty string to the AttachedTemplate property:

    ActiveDocument.AttachedTemplate=""

    Of course that would mean you have to pre-process the documents used by your application first (which still will be slow). But afterwards the documents should open up just fine.

    Luca

    • Proposed as answer by Terry Xu - MSFT Monday, February 5, 2018 9:03 AM
    • Marked as answer by mspeninsula Tuesday, February 6, 2018 3:06 AM
    Friday, February 2, 2018 11:14 AM
  • It's helpful. Thanks very much!
    Tuesday, February 6, 2018 3:06 AM