Unable to create a Word 2007 template .dotx in VB6 RRS feed

  • Question

  • Hi,

    I'm trying to upgrade a VB6 application that Interfaces with Word to use Word 2007. Currently the aplication uses Word2003. 

    One of the things my application is designed to do is to programmatically create new Word templates and as I say the code works fine when Word 2003 is installed.

    I have created the code below to demonstrate my problem with a simple button click.
    The code creates a new Template called 'MyTemplate.dotx' in the folder 'C:\temp', however when I try to open the newly created template in Word 2007 I receive an error stating that 'Word experienced an error trying to open the file.' and suggests that I 'Open the file with the Text Recovery Convertor.' The Recovery Convertor however fails.

    If I change the extension to .zip and examine the files contained therin I only have the following:


    I'm missing (amongst other things) document.xml

    What I have noticed is that if I rename the extension to .dot the template opens in compatibility mode without error. However, I need my new template to be a true Word 2007 format template.

    Private Sub Command1_Click()

    Dim obWord As Word.Application
    Dim spath As String

      On Error GoTo ErrorHandler

          'Create directory
          spath = "C:\temp"
          If Dir(spath, vbDirectory) = "" Then
            MkDir spath
          End If
          spath = spath & "\MyTemplate.dotx"
          'Create new word document
          Set obWord = New Word.Application
          obWord.ActiveDocument.SaveAs fileName:=spath, FileFormat:=wdFormatTemplate
      Exit Sub
      Err.Raise Err.Number
    End Sub
    Can anyone see where I am going wrong?

    Any advice or suggestions on this would be gratefully received.

    Many thanks,

    • Moved by Cindy Meister MVP Friday, January 8, 2010 7:27 AM not VSTO-related (From:Visual Studio Tools for Office)
    Friday, January 8, 2010 1:29 AM


  • VSTO is a .NET technology that gives .NET developers tools for expanding the Office application UIs. VB6 and VBA are not supported in this forum. The Please Read First message pinned at the top of the forum gives further details, as well as links to venues for non-VSTO, Office-related topics.

    I'm going to move your question to off-topic. I recommend to you the word.vba newsgroup, as the object model/syntax problem is going to be the same for you.

    FWIW, I strongly urge you to look at the Enum for FileFormat:=wdFormatTemplate. You're not using the correct setting.
    Cindy Meister, VSTO/Word MVP
    • Marked as answer by RedHotAnt Friday, January 8, 2010 9:57 PM
    Friday, January 8, 2010 7:26 AM