ActiveDocument.Unprotect not prompting for password in Word 2003 (and Word 2007)

R

RobertSeattle

Contrary to the documentation, if the ActiveDocument has document
level protection turned with a password, ActiveDocument.Unprotect
doesn't prompt for a password like it did id Word 97, 2000, or 2002.
Anyone have a workaround other than trapping the failure and prompting
with custom "password" dialog? Thanks.
 
P

Perry

You can try a sequence like below code listing

Dim doc As Document
Dim bUnprotect As Boolean
Set doc = ActiveDocument
Dim sPWD As String

'if you have a default password
'then prepopulate variable sPWD
sPWD = "yeah:"

If doc.ProtectionType > -1 Then

Do While Not bUnprotect
On Local Error GoTo ErrProtect
doc.Unprotect sPWD
bUnprotect = True
Loop
Else
bUnprotect = True
End If
ExitHere:
If bUnprotect = False Then
'you might want to close
'Activedocument without saving changes here
'because you weren't able to lift protection
End If
Exit Sub
ErrProtect:
sPWD = InputBox("Enter password")
If sPWD = "" Then
bUnprotect = False
Resume ExitHere
Else
Resume
End If

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 
R

RobertSeattle

Perry,

Thanks.
I'm doing something similar with a form since I want the UI to look
just like the password prompt looks like the built-in one. (and the
password appears masked). Pretty lame the help documentation for
the .Unprotect method has been wrong for TWO versions of Word now and
it hasn't been fixed. The help authors need to check do more than
edit/replace version # numbers! :)
 
P

Perry

As to your observations:
Yes, you are right.

As to masking passwords:
If you want a popup/dialog to show up with a masked password entry control,
create/design
a userform including a textbox and set the .PassWordChar() property
according to your liking.

--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 

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