Problems with ActiveDocument.AttachedTemplate when using protected (forms) template

S

SteveV

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
 
C

Charles Kenyon

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
 
S

SteveV

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top