Detect protected document in W 2k3

W

Wowbagger

In Word 2k3, how do I detect if a document is protected? My help searches
keep coming up with ActiveDocument.protect but that doesn't have a
true/false value.

--
Thanks

"He had had his immortality thrust upon him by an unfortunate accident with
an irrational particle accelerator, a liquid lunch and a pair of rubber
bands. The precise details of the accident are not important because no one
has ever managed to duplicate the exact circumstances under which it
happened, and many people have ended up looking very silly, or dead, or
both, trying."
 
C

Charles Kenyon

The following macro contains one method:

Public Sub ProtectForm()
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, _
noreset:=True
Else
ActiveDocument.Unprotect
End If
End Sub


--

Charles Kenyon

See the MVP FAQ: <URL: 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.
 
J

Jay Freedman

Wowbagger said:
In Word 2k3, how do I detect if a document is protected? My help searches
keep coming up with ActiveDocument.protect but that doesn't have a
true/false value.

You check the value of ActiveDocument.ProtectionType. If it's equal to
wdNoProtection then the document is not protected. It may have values
of wdAllowOnlyComments, wdAllowOnlyFormFields, wdAllowOnlyReading, or
wdAllowOnlyRevisions -- these correspond to the choices in the Tools >
Protect Document task pane, in the dropdown under Editing
Restrictions.

You can use a simple If...Then construction if you just want to know
whether there is any protection, or you can use a Select Case
construction if you need to know which type of protection exists. For
and example of the latter, see the article at
http://word.mvps.org/FAQs/MacrosVBA/SpellcheckProtectDoc.htm.
 

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