Returning Protection Type from wdDialogToolsProtectDocument dialog

J

John W.

Hello,

I am trying to write a program that creates a bunch of password protected
documents. To do so, I am running the following code:

With Dialogs(wdDialogToolsProtectDocument)
PasswordResponse = .Display
ProtectionType = .Type
Password = .DocumentPassword
End With

The VBA help titled "Built-in Dialog Box Argument Lists" includes the
argument Type as one of this particular dialog box's arguments.
Unfortunately, no matter what protection type is selected, the variable
ProtectionType always returns the value 503 (the type of the dialog box, not
the protection type). I understand why this is occurring, but is there any
way to get the protection type for further use?

Thanks a lot for your help!
 
J

Jean-Guy Marcil

John W. said:
Hello,

I am trying to write a program that creates a bunch of password protected
documents. To do so, I am running the following code:

With Dialogs(wdDialogToolsProtectDocument)
PasswordResponse = .Display
ProtectionType = .Type
Password = .DocumentPassword
End With

The VBA help titled "Built-in Dialog Box Argument Lists" includes the
argument Type as one of this particular dialog box's arguments.
Unfortunately, no matter what protection type is selected, the variable
ProtectionType always returns the value 503 (the type of the dialog box, not
the protection type). I understand why this is occurring, but is there any
way to get the protection type for further use?

Have you tried working with:

ActiveDocument.ProtectionType

???
 
J

John W.

Have you tried working with:
ActiveDocument.ProtectionType

???

Yes, unfortunately I don't want to protect the document yet (which is why I
used .Display as opposed to .Show). At this point in the code, the document
has whatever protection type it had originally. The user will be choosing
the new protection type, which will be passed later.
 
G

Gordon Bentley-Mix

John,

The behaviour you are seeing is expected. The value of the .Type property
you are recording in your "ProtectionType" variable _does not_ specify the
protection type of the document. Rather it specifies the .Type property of
the dialog - which is 503.

In addition, I the course of my investigations I have determined that, if a
document is protected, many of the properties of this dialog cannot be
accessed. This includes the .Password property. I expect that this is by
design and is intended to prevent "cracking" the protection of a document
through VBA.

I suggest you look again at Jean-Guy's recommendation to work with the
..ProtectionType property of the document. This will give you the information
you desire. Something like the following should get you pointed in the right
direction:

Sub Test()
Dim myProtectionType As Integer
Dim myDoc as Document
Set myDoc = ActiveDocument
myProtectionType = myDoc.ProtectionType
'Do whatever else you need to do, including unprotecting the document
'(if necessary), collecting the "new" protection type from user input and
'applying this new protection type using the Protect method.
End Sub

Note that if you need to unprotect the document as some point, you will have
to write code to do so using the Unprotect method and supplying the password
if needed. And as mentioned above, you probably won't be able to determine
the password programmatically.

If you do re-protect the document again, please be aware that there are
additional arguments associated with Protect method that you may also need to
consider. These are discussed in the VBA Help topic on the "Protect Method".
--
Cheers!
Gordon

Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
 

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