locked
How does Word resolve references to templates and add-ins (particularly across platforms)? RRS feed

  • Question

  • Hello,

    Can anyone explain how Word resolves template names and macro references in documents? What happens when you move a document between computers, particularly if they're running different versions of Word (e.g., Mac vs Windows)?

    More specifically, Word seems to store references to document templates and add-ins using full pathnames, but what happens if you open the document on another computer where these pathnames aren't valid? Does Word make some attempt to locate a template or add-in with the same name, and if so, is this behaviour documented anywhere, and is it reliable, particularly across platforms?

    The reason I ask is because I'm in the process of porting some macros and templates from Word 2003 to Word 2011, and I've run into some problems in this area. The scenario is as follows:

    1. Documents are created using a set of standard document templates that refer to a global add-in - everybody configures their version of Word to load the add-in at startup, and makes a local copy of the template folder or links to the shared template folder, depending on their network setup.

    2. Word 2003 is able to resolve the template reference, even if the location of the template is different on the local machine.

    3. Word 2003 is also able to resolve the macro reference in the template, which links to the copy of the add-in that was loaded at startup - in fact, the reference stored in the template is deliberately broken to force this to happen.

    However, Word 2011 doesn't resolve these references correctly - in particular, it doesn't recognise the document template, which contains an Auto Open macro that should run whenever a document is opened, and the macro reference doesn't resolve unless the add-in is stored in the template folder rather than loaded at startup.

    I realise that PC pathnames have a different format from Mac pathnames, but if Word is capable of resolving references based on the name of the template or macro rather than its full pathname, then in principle, this should work across platforms.

    Can anyone explain what is going on and suggest a possible workaround?

    Thanks.

    Robert

    Wednesday, October 12, 2011 7:44 PM

Answers

  • Hi Robert,

    I might be able to help you with part of your question.

    Word 2011 for the Mac suffers from a time delay problem and AutoOpen, AutoNew, Document_Open, and Document_New events don't fire until Word's Normal template has been fully loaded. I've found that you must have a little patience and then the events will fire. This is my workaround for getting the Document_New and Document_Open events to work in my templates.

    Hope it helps

    Sub AutoNew()
        HavePatience
    End Sub
    Sub AutoOpen()
        HavePatience
    End Sub
    Sub HavePatience()
        
        If StopCount > 9 Then
            MsgBox "Sorry, your document failed to open."
                StopCount = 0
                End
        End If
    
        StopCount = StopCount + 1
    
        weThereYet = Application.Documents.count
    
        If weThereYet < 1 Then Application.OnTime _
            Now + TimeValue("00:00:01"), "HavePatience"
        
    End Sub
    
    

     


    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by Rex Zhang Monday, October 17, 2011 2:39 AM
    Wednesday, October 12, 2011 9:07 PM

All replies

  • Hi Robert,

    I might be able to help you with part of your question.

    Word 2011 for the Mac suffers from a time delay problem and AutoOpen, AutoNew, Document_Open, and Document_New events don't fire until Word's Normal template has been fully loaded. I've found that you must have a little patience and then the events will fire. This is my workaround for getting the Document_New and Document_Open events to work in my templates.

    Hope it helps

    Sub AutoNew()
        HavePatience
    End Sub
    Sub AutoOpen()
        HavePatience
    End Sub
    Sub HavePatience()
        
        If StopCount > 9 Then
            MsgBox "Sorry, your document failed to open."
                StopCount = 0
                End
        End If
    
        StopCount = StopCount + 1
    
        weThereYet = Application.Documents.count
    
        If weThereYet < 1 Then Application.OnTime _
            Now + TimeValue("00:00:01"), "HavePatience"
        
    End Sub
    
    

     


    Kind Regards, Rich ... http://greatcirclelearning.com
    • Marked as answer by Rex Zhang Monday, October 17, 2011 2:39 AM
    Wednesday, October 12, 2011 9:07 PM
  • Hi, I have the same issue,

    I tried the above suggested way, but it is not working

    I am just trying to call one message box in the Document_New () method

    below is the code I am using and no message box is popped up, let me know work around

    Private Sub Document_New()
    MsgBox "test"
    End Sub


    • Edited by hardikkumar Monday, September 16, 2013 11:17 PM
    Monday, September 16, 2013 11:14 PM
  • Did you put the AutoNew and AutoOpen code that I reference above into the ThisDocument class where your Document_New event is?

    Kind Regards, Rich ... http://greatcirclelearning.com

    Monday, September 16, 2013 11:24 PM