Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Dec 2000
    Location
    Kansas
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem changing template in code (Word 2002`)

    I would like to set a new document template in AutoNew. However, I get the following error message: "Could not change document template" The error number is 5947. In fact, Word often crashes altogether and I get the "Microsoft Word has encountered a problem and needs to close. We are sorry for the inconvenience." dialog. The "To see what data this error report contains" locates the problem in MOdName: vbe6.dll, ModVer 6.3.91.8, Offset: 0000a6e2. I tried replacing the vbe6.dll, but the error still occurs.

    This is the code which causes the problem:

    Sub AutoNew()

    On Error GoTo ErrHandler

    ' Help says the following syntax should work,
    ' but it doesn't. Path and filename are correct.

    With ActiveDocument
    .ActiveDocument.AttachedTemplate = "Cocuments and Settingsongho_2Application DataMicrosoftTemplatesLetter.dot"
    Selection.Style = ActiveDocument.Styles("Body Text")
    End With

    Exit Sub


    ErrHandler:
    If Err <> 0 Then

    ' Display an error message.
    MsgBox Err.Description & " - Error number is " & Err.Number _
    & ", located in " & Err.Source

    End Sub

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Problem changing template in code (Word 2002`)

    The syntax

    <pre>With ActiveDocument
    .ActiveDocument.AttachedTemplate = "Cocuments and Settingsongho_2Application
    </pre>

    Is equivalent to
    <pre>ActiveDocument.ActiveDocument.AttachedTemplat e = "Cocuments and Settingsongho_2Application
    </pre>

    which has one too many ActiveDocuments.

    If I try to run your code then I get run time error 438. "Object doesn't support this property or method" which is what I would expect since the ActiveDocument doesn't have an ActiveDocument property.

    Try leaving out the .ActiveDocument at the beginning of the second line and see what happens.

    StuartR

  3. #3
    New Lounger
    Join Date
    Dec 2000
    Location
    Kansas
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Problem changing template in code (Word 2002`)

    Hi Stuart,

    Thanks for the reply, pointing out the double use of the "ActiveDocument" keyword. I immediately went to my code, but alas, my code was correct, I merely copied it incorrectly in my earlier post here.

    Since I posted, I've been doing a little experimenting, and I've been able to get the code to work with other templates -- it looks like the particular template I was using is corrupted. Rats, I'll have to rebuild the template, if I can't find a backup.

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •