none
Can add new template. Cannot open existing template RRS feed

  • Question

  • Hi, using the following I can successfully create a Word 2010 template. However, when an existing template is found it cannot be opened.

            If existingTemplate Then
                Set wordTemplate = Documents.Open(documentFullName)
            Else
                'Otherwise create template.
                Set wordTemplate = Documents.Add
                ActiveDocument.SaveAs documentFullName
            End If
    The variable documentFullName = "S:\SSP\Word Templates\2010 template.dotx"

    The error is 'Error 6102' (Word encountered an error processing the xml file 2010 template.dotx No error detail available) in procedure...'

    The documents.open statements works successfully when the file extension is .dot or .docx

    Can you think of any reason that the above is not able to open a 2010 template?

    Many thanks,


    Jonathan

    Sunday, October 6, 2013 7:54 PM

Answers

  • i'm not in a position where i can look this up for you,but check the wdformat enumeration. i think your code is saving as the older template file format, not the new one (xml). but you're assigning the new file extension. setting the compatibility operator won't help with this.

    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Kiwi Jonathan Tuesday, October 8, 2013 10:25 PM
    Tuesday, October 8, 2013 10:11 PM
    Moderator

All replies

  • Hi, more information...

    I tried to manually open the template created and get this error message in Word 'The file 2010 template.dox cannot be opened because there are problems with the contents.'

    After the statement ActiveDocument.SaveAs documentFullName I simply closed the template so that there is no content. So any ideas what I need to change?

    Many thanks,


    Jonathan

    Sunday, October 6, 2013 8:34 PM
  • It seems the word file is broken.

    Would you mind sharing 2010 template.dotx?

    Monday, October 7, 2013 5:37 AM
  • Hi I have tried this processes without any contents in this template (it is simply a blank document) and still the process fails. I have tried changing to  SaveAs2 to resolve this issue - no success.

    Many thanks,


    Jonathan

    Tuesday, October 8, 2013 3:59 AM
  • Hi Jonathan

    Please explain how the template was created.

    Does this occur with any template file (*.dotx) or only this one file? If with any file, were all templates generated on the same system (under the same user profile)?

    If you save a new *.dotx to the local drive and try to open it from there does that work?

    Please note that you must specify a template data type in SaveAs in order to create a template from a document file. It's not enough to simply give the file the extension *.dotx. That extension will not match the internal content type inside the document, which will prevent Word from opening it successfully. Is that the problem?


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, October 8, 2013 3:45 PM
    Moderator
  • Hi Cindy,

    The template is created in Access 2010 using the following

        'Reference an existing Word session.
        On Error Resume Next
        Set gWordApplication = GetObject(, "Word.Application")
        If Err.Number <> 0 Then
            Err.Clear
            On Error GoTo Err_wordGetTemplate
            'Open a new Word session.
            Set gWordApplication = CreateObject("Word.Application")
        End If
        On Error GoTo Err_wordGetTemplate
            
        With gWordApplication
            'Check whether to create template.
            wordExtensionsList(0) = ".dot"
            wordExtensionsList(1) = ".dotm"
            wordExtensionsList(2) = ".dotx"
            
            For extensionIndex = 0 To UBound(wordExtensionsList())
                fileExtension = wordExtensionsList(extensionIndex)
                If (Len(Dir(documentFullName & fileExtension)) > 0) Then
                    existingTemplate = True
                    Exit For
                End If
            Next extensionIndex
            
            documentFullName = documentFullName & fileExtension
            
            If existingTemplate Then
                Set wordTemplate = .Documents.Open(documentFullName)
            Else
                'Otherwise create template.
                Set wordTemplate = .Documents.Add
    '            .ActiveDocument.SaveAs documentFullName, wdFormatTemplate
                .ActiveDocument.SaveAs2 documentFullName, wdFormatTemplate, , , , , , , , , , , , , , , wdWord2010
            End If
    

    I have tried to reference the word applcation with Set gWordApplication = New Word.Application and this also fails to saveas. I prefer not to use this anyway to avoid the need for early binding.

    documentFullName = "S:\SSP\Word Templates\2010 template.dotx"

    Now the error I am getting when executing the saveas statement is 'Incompatible file type and file extension'. Interesting is that this statement did not trigger an error before; it was the open?!

    When I have documentFullName = "S:\SSP\Word Templates\2010 template.dot" the save is successful. Don't want this because when later adding content to the template will have format compatibility issue.

    When I manually open word and save a template with this name (blank content) and then use the above code to open the template this is successful.

    Many thanks,


    Jonathan

    Tuesday, October 8, 2013 8:33 PM
  • Hi Cindy,

    I was re-reading my reply and noticed that I had not directly answered your questions.

    Q:Does this occur with any template file (*.dotx) or only this one file? If with any file, were all templates generated on the same system (under the same user profile)?

    A: Only happens with *.dotx. Doesnt happen with *.dot. Same error 'Incompatible file type and file extension' when executing this function on another pc and/or user profile.

    Q:If you save a new *.dotx to the local drive and try to open it from there does that work?

    A: Same error message regardless of name and destination folder location.

    Note: Please note that you must specify a template data type in SaveAs in order to create a template from a document file.

    A: The .SaveAs2 also includes compatibilty parameter. Still no success.

    Many thanks,


    Jonathan

    Tuesday, October 8, 2013 9:20 PM
  • i'm not in a position where i can look this up for you,but check the wdformat enumeration. i think your code is saving as the older template file format, not the new one (xml). but you're assigning the new file extension. setting the compatibility operator won't help with this.

    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Kiwi Jonathan Tuesday, October 8, 2013 10:25 PM
    Tuesday, October 8, 2013 10:11 PM
    Moderator
  • Hi Cindy,

    Brilliant, I kept thinking that I had the correct wdformat. But your observation got me to recheck the list and found this one and it works like a charm. :-)

    Const wdFormatXMLTemplate = 14

    Many thanks.


    Jonathan

    Tuesday, October 8, 2013 10:25 PM