Problem 1: ActiveDocument.AttachedTemplate =
sMyNewFullyQualifiedTemplatePath
results in the following error:
Run-time error '5598'
Word cannot attach a document to a protected template
Problem 2: There appears to be no way to unprotect a template, which
in the case a doc template with many, many form fields. Leaving the
template unprotected is not an option as I need to prevent users from
messing with the form fields and document layout and I need to have
the form fields function as, um well, form fields.
Here is my code:
Set curTemplate = ActiveDocument.AttachedTemplate
Dim sCurTemplatePath As String
sCurTemplatePath = curTemplate.Path & Application.PathSeparator &
curTemplate.Name
If StrComp(sCurTemplatePath, sTargetTemplatePath, vbTextCompare) <> 0
Then
UnprotectForm
ActiveDocument.AttachedTemplate = sTargetTemplatePath
ProtectForm
Dim sMsg As String
sMsg = "Fixed incorrect Clinic Note Template location." & vbCrLf &
vbCrLf & "Old: " _
& sCurTemplatePath & vbCrLf & vbCrLf & "New: " &
sTargetTemplatePath
MsgBox sMsg, vbInformation + vbOKOnly, "Relinking Clinic Note
Template"
End If
Does anyone have any insight as to how it might get this to work?
Thanks in advance!
--Steve
SteveV - 05 Nov 2004 01:14 GMT
Anyone?
> Problem 1: ActiveDocument.AttachedTemplate =
> sMyNewFullyQualifiedTemplatePath
[quoted text clipped - 41 lines]
> Thanks in advance!
> --Steve
Charles Kenyon - 05 Nov 2004 02:01 GMT
Unprotect your template but
(1) Use an AutoNew macro to proctect any documents created from the
template upon creation, and
(2) Make the template read-only

Signature
Charles Kenyon
Word New User FAQ & Web Directory: http://addbalance.com/word
Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide
See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
> Problem 1: ActiveDocument.AttachedTemplate =
> sMyNewFullyQualifiedTemplatePath
[quoted text clipped - 41 lines]
> Thanks in advance!
> --Steve
SteveV - 08 Nov 2004 19:36 GMT
Thanks Charles. You suggestion does work but causes some potential
problems: Specifically, if the user opens an existing doc based on
this template but does not have the template installe don their
machine the protect document macro will never run. This would allow
the user to overwrite (and thereby delete) the form fields. And
should the user decide to turn on document protection from the Tools
menu on Word versions prioir to 2003, all of their form data would be
reset.
Make me wonder if the folks at MS use Word and VBA in "real life"
situations.
Thanks again,
Steve
> Unprotect your template but
> (1) Use an AutoNew macro to proctect any documents created from the
[quoted text clipped - 46 lines]
> > Thanks in advance!
> > --Steve