|
-
Sep 12th, 2005, 08:13 AM
#1
Thread Starter
Junior Member
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:
Sub FixTemplate()
Set sCurrentTemplate = ActiveDocument.AttachedTemplate
sCurrentTemplate = LCase(sCurrentTemplate)
sOldTemplate = LCase("\\some_server\share\missing_template.dot")
If sCurrentTemplate = sOldTemplate Then
ActiveDocument.AttachedTemplate = "C:\program files\templates\text97.dot"
End If
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?
-
Sep 12th, 2005, 02:42 PM
#2
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:
Sub remove_templates()
Dim dkTmplt As Template
For Each dkTmplt In Application.Templates
If dkTmplt.Name <> "normal.dot" Then
AddIns(dkTmplt.FullName).Delete
End If
Next dkTmplt
End Sub
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Sep 13th, 2005, 12:24 AM
#3
Thread Starter
Junior Member
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.
-
Sep 13th, 2005, 09:39 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|