How do you find out if a template is protected for Forms with pass

K

koolnuts

I have several templates which are protected for Forms some with a password
and some without a password.

What I need to do via VBA is to be able to identify if a template is
protected for Forms with a password or without before I unprotect the
template either using the password or an empty string. I then do some further
processing on the template and then reprotect it.

I know you can check if a template is password protected by checking the
HasPassword property, but I have not been able to find a similar property
which will tell me if the template is protected for Forms with a password.

Does anyone know if this is possible or if there is any work around it?

I would really appreciate any help.
 
J

Jezebel

The method suggested in the Help file looks reasonable --

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=strPassword
End If
 
K

koolnuts

Hi Jezebel

That is the type of code I am using, but I need to be able to change the
strPassword value through code depending on whether the ActiveDocument is
protected for Forms with a password or without a password. The ActiveDocument
is protected for Forms, I just need to identify if it has a "real" password
or if it is protected but without a password and change the value of the
strPassword variable to reflect this condition before I try to unprotect it.

I don't want any user interaction here, just the code doing what it is
supposed to do.

Is there a way of doing this?
 
J

Jezebel

Try it and trap the error.




koolnuts said:
Hi Jezebel

That is the type of code I am using, but I need to be able to change the
strPassword value through code depending on whether the ActiveDocument is
protected for Forms with a password or without a password. The
ActiveDocument
is protected for Forms, I just need to identify if it has a "real"
password
or if it is protected but without a password and change the value of the
strPassword variable to reflect this condition before I try to unprotect
it.

I don't want any user interaction here, just the code doing what it is
supposed to do.

Is there a way of doing this?
 
K

koolnuts

I am trapping for Err.Number = 5485 ("The password is not correct" error) but
before it goes to the error handler and runs the code specific to this error
it brings up the "Unprotect Document" password dialog box which the use then
needs to click on before the program will then continue - which I don't want.

So I need to either:

1: find out how to identify if the document is protected with a password and
use the correct password when trying to unprotect the document; or

2: bypass the "Unprotect Document" password dialog box and then set the
password variable value in the Error_Handler and Resume execution.

Any ideas?
 

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