Results 1 to 9 of 9
  1. #1
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Attaching a template (Word 2000/SR 2)

    I am in the process of developing a COM addin whose purpose is to attach a specific template to a document when a document is opened. I would go into why this procedure is required but that would be very long so I won't. Anyway I discovered that if a template is "Protected" then a document cannot be attached to it and it appears there is going to be a requirement that a template is protected. If that is the case the addinwill have to first open the template, unprotect it, save it and then attach it and at some time open the template again, protect it and save it again. My question is, is there a way to set the protection status of a template without opening it?

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

    Re: Attaching a template (Word 2000/SR 2)

    >> is there a way to set the protection status of a template without opening it?

    I don't think so, but perhaps one of the Word gurus will come up with a brilliant solution. You can read and modify the document summary properties of an Office document without opening it using the DSOFile DLL available from Microsoft, but the protection status is not a summary property.

    Would it be feasible to leave the template unprotected? If documents based on the template need to be protected, you can use the Document_New event to protect a document immediately after it has been created from the template.

  3. #3
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching a template (Word 2000/SR 2)

    Thanks that is what I figured. Yes I have suggested that the template be unprotected just as Microsoft installs their Word templates unprotected but a decision has not been made yet.

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Attaching a template (Word 2000/SR 2)

    I probably don't have an answer for you, but what kind of protection are you referring to: document content protection (Tools > Protect), or code protection for the macros, or some other kind of protection? Can create a new document using the template, as opposed to attaching an existing document to it?

  5. #5
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching a template (Word 2000/SR 2)

    I am referring to the protection of the document such as forms, comments, and not the macros. If a template has protection turn on then one can still derive a document from it but one canot attach a document to the template.

  6. #6
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Attaching a template (Word 2000/SR 2)

    Very odd. It works just fine when done by the user, but these event procedures are so touchy.

  7. #7
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching a template (Word 2000/SR 2)

    I am not sure what you are referring to in your last reply "It works just fine when done by the user...". If you create a word template, set protection on it(Tools|Protect Document...) and save it( I save the template to my user define templates area) When I try to attach a template to it using "tools|Templates and AddIns..." I get the message that a document cannot be attached to a protected template( see attachment ).
    Attached Files Attached Files

  8. #8
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Attaching a template (Word 2000/SR 2)

    My mistake, I use a custom macro for this because our document management system disables the native dialog. My code is this, and it allows me to attach a document to a protected template interactively in Word 2002. Not sure if this helps you!
    <pre>reStart:
    With Dialogs(wdDialogToolsTemplates)
    On Error GoTo badFileName
    If .Display = -1 Then
    ' user clicked OK, change the attached template
    'MsgBox .Template 'for debug only
    '.Execute
    ' do not use Execute! must make the change manually
    ' to avoid unloading the global templates
    ActiveDocument.AttachedTemplate = .Template
    ' NOTE: if the user deleted the template name to a blank,
    ' the template will be set to "Normal" and no error occurs
    Else
    ' user clicked Cancel, just do nothing
    End If
    End With
    ' if you were to run the native Templates dialog right now, the
    ' add-ins would be un-checked, but this is not true; not sure why
    ' this happens, but if you close and re-open the native dialog,
    ' they are properly checked...go figure!
    Exit Sub

    badFileName:
    ' if user first inputs an invalid name and clicks OK, the dialog does not
    ' even if the final name is invalid, an error occurs upon close, so here
    ' we are and back we go
    MsgBox "Problem finding that template. Please try again, or leave the template name blank."
    GoTo reStart</pre>

    P.S. My test template was located in a c:WestlawBilling folder and protected for tracked changes with the password asdf.

  9. #9
    3 Star Lounger
    Join Date
    Nov 2002
    Posts
    387
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Attaching a template (Word 2000/SR 2)

    Thanks I will give that a try on Word 2000 using forms protection, I have to run out at the moment but wanted to thank you for all of the trouble you went to. In the end I want to be able to attach to a template via VBA code, behind the scenes where the user is not aware this is going on. It is a requirement thing.

Posting Permissions

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