Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

ActiveDocument.Unprotect does not prompt for password

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peter - 25 Sep 2007 16:22 GMT
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
fumei - 25 Sep 2007 17:22 GMT
Can you post your code?
Peter - 25 Sep 2007 18:36 GMT
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.

> Can you post your code?
Peter - 27 Sep 2007 16:22 GMT
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

> Public Sub URS_Unlock()
>     On Error GoTo Errorhandler
[quoted text clipped - 13 lines]
>
> > Can you post your code?
Graham Mayor - 28 Sep 2007 08:45 GMT
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

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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
[quoted text clipped - 24 lines]
>>> Message posted via OfficeKB.com
>>> http://www.officekb.com/Uwe/Forums.aspx/word-programming/200709/1
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.