Results 1 to 4 of 4

Thread: Problems setting a new template

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    16

    Problems setting a new template

    Hi all,

    We've got a bunch of documents that have a template attached with a path that no longer exists. I'm making a small macro which replaces the non-existing path with a new one, but I've run into some problems.

    It seems that if the missing template isn't found, the document defaults to Normal.dot (fair enough). But, I want to pull the path of the missing template out of the document. My code is:

    VB Code:
    1. Sub FixTemplate()
    2. Set sCurrentTemplate = ActiveDocument.AttachedTemplate
    3.  sCurrentTemplate = LCase(sCurrentTemplate)
    4.  
    5. sOldTemplate = LCase("\\some_server\share\missing_template.dot")
    6.  
    7. If sCurrentTemplate = sOldTemplate Then
    8.     ActiveDocument.AttachedTemplate = "C:\program files\templates\text97.dot"
    9. End If
    10.  
    11. End Sub

    This would work beautifully, except that ActiveDocument.AttachedTemplate is "Normal.dot" (since the otehr one can't be found). However, in the Templates and Add-Ins dialog, the path to the missing template is available.



    Since the path is still there, I figure there's gotta be some way to pull it out, but damned if I can find it. Any hints?

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Problems setting a new template

    Rather than looking ActiveDocument.AttachedTemplate, which in the case where the other template path cannot be resolved will always be the normal.dot, you need to look at all available templates in the instance of the word application.
    I would suggest that you delete all the non-applicable references then add your new template.
    Note: you cannot delete from the templates collection, but only from the AddIns collection.


    VB Code:
    1. Sub remove_templates()
    2.     Dim dkTmplt As Template
    3.    
    4.     For Each dkTmplt In Application.Templates
    5.        
    6.         If dkTmplt.Name <> "normal.dot" Then
    7.             AddIns(dkTmplt.FullName).Delete
    8.         End If
    9.    
    10.     Next dkTmplt
    11.  
    12. End Sub
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Posts
    16

    Re: Problems setting a new template

    Thanks for replying! I thought of this too, but the Templates collection only contains loaded templates, not the ones that aren't resolved.

  4. #4
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Problems setting a new template

    Ahh! When the template reference cannot be found it is removed from the Templates collection. It is still a member of the AddIns collection and has .Installed=False

    So, edit the code above and try looping through the AddIns collection, deleting where not installed might be a solution.
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

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



Click Here to Expand Forum to Full Width