Results 1 to 7 of 7
  1. #1
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Attaching a new template (VBA/Word/2000)

    Dialogs(wdDialogToolsTemplates).Show

    When running the above line of code from the Immediate window, the selected template is attached to the active Word document. However running the same line of code within a procedure that is saved in the active document, I am advised of
    <hr>Run-time error '5947':
    Could not change document template.<hr>
    Where have I erred?
    Regards
    Don

  2. #2
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching a new template (VBA/Word/2000)

    Can't reproduce... but am using Word2003 currently.

    Can you post the doc containing the macro?

    <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16> Klaus

  3. #3
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Attaching a new template (VBA/Word/2000)

    Hi Klaus
    I solved my immediate problem by inserting the Documents.Add DocumentType:=wdNewBlankDocument line in the query procedure (4th line below). If I rem out that line the problem re-appears.


    <pre>Public Sub query(Optional test As Boolean)
    Dim resp As Byte
    Dim msg As String
    Documents.Add DocumentType:=wdNewBlankDocument
    If Len(Selection) > 25 Then
    Selection.Collapse
    msg = "The KeyBindings have already been" & vbCrLf
    msg = msg & "captured and saved in this file." & vbCrLf & vbCrLf
    msg = msg & "If the current information is of no value or if" & vbCrLf</pre>



    The macro runs on opening, but there is also a "test" procedure to call it. If running from the "test' procedure; ensure that all text has been deleted from the document first.

    TIA
    Regards
    Don

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Attaching a new template (VBA/Word/2000)

    The problem seems to be in the line

    ThisDocument.Activate

    in Sub Main. If you take that out, the code will run without the need to create a new document. I don't know why explicitly activating the document causes this problem.

  5. #5
    5 Star Lounger
    Join Date
    May 2001
    Location
    Stuttgart, Baden-W, Germany
    Posts
    931
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching a new template (VBA/Word/2000)

    Strange: I don't get an error either in Word2003 or Word2000, with or without the line to add a new doc.

    Klaus

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Attaching a new template (VBA/Word/2000)

    Strange indeed - I did get the error that Don Wells reports in Word 2002 SP-3.

  7. #7
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Attaching a new template (VBA/Word/2000)

    Thanks Hans
    Regards
    Don

Posting Permissions

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