ActiveDocument.Unprotect does not prompt for password

P

Peter

Hi,

I have a form I developed in Word 2000. The form is password protected and I
have created a pull-down menu item that allows users to unprotect the
document (only those select users that know the password). According to VBA
help, if a document is protected with a password and no password is given in
the ActiveDocument.Unprotect call, then the user will be prompted for the
password. This is how it worked in Word 2000. Now I've upgraded to Word 2003
and while the VBA help still states the user will be prompted for a password,
instead I get an error message stating the password is incorrect.
Anyone have any ideas why or how to fix this?

Thanks,
Peter
 
P

Peter

Public Sub URS_Unlock()
On Error GoTo Errorhandler
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect
End If
End With
Errorhandler:
If Err.Number > 0 Then
MsgBox Err.Description, vbCritical + vbOKOnly, "URS Unlock failed"
End If
End Sub

The error description is: "The password is incorrect." In Word 2000, this
code prompted for a password.
 
P

Peter

Ok, I posted my code two days ago. The forms toolbar padlock icon prompts for
a password but my code does not work. If I go to another computer with word
2000 and open the exact same document, it works. If I open with word 2003, it
doesn't.

Peter
 
G

Graham Mayor

I no longer have access to Word 2000 to check, but Word 2003 works as you
indicate. The vba help has not been updated (and still has not in Word 2007)
and so is misleading. It does however say

"If a password is required in a procedure, request the password from the
user, store it in a variable, and then use the variable in your code"

so

Public Sub URS_Unlock()
Dim sPassword As String
sPassword = ""
Start:
On Error GoTo Errorhandler:
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect (sPassword)
End If
End With
Errorhandler:
If Err.Number = 5485 Then
sPassword = InputBox("Enter password", "Unprotect")
GoTo Start:
End If
End Sub

should work with either version

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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