Macro to protect/unprotect document

R

Ricki Miles

I am creating a template in Word 2003 that is protected for form fields. I
would like a macro to unprotect the form (retaining the data in the form
fields) so that users can edit the footer. I would like another macro to
reprotect the form. I currently have a macro for each that will unprotect
and reprotect, but if the document is protected and the protect macro is
run, an error occurs. Similarly, if the document is unprotected and the
unprotect macro is run, an error occurs as well. How can I change the VBA
code so that if the document is already protected and the protect macro is
run, nothing happens and the same for unprotect. Below is the code I was
using. Thanks,

Ricki

If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
Else
ActiveDocument.Unprotect
End If
 
G

Graham Mayor

Why not simply use the lock button from the forms toolbar?

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=""
End If

'Reprotect the document.
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
I

iris b

Hi Graham,

I saw your reply to ricki... I need to add some more code to this...

I need to unprotect a word document with these steps:

1. create a message to the user "enter password"
2. if password is correct then - unprotect
end if
3. if password is not correct then
create a messeage: "uncorrect password"
end if

I dont know how to prompt the message and use it's text box for "true" or "false" unswers.

Thank you in advance

iris
 

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