Macro to Unlock a Locked Word 2007 Document

W

WordWorker

Is it possible -- and how do I do it -- to write a macro that a text input
field will run to temporarily unlock a locked Word 2007 form? I wrote one
that will lock the document that will run "On exit" from a field, but no
matter how I phrase it I can't get a macro to unlock the doc.
 
G

Greg Maxey

Sub OnExit()
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
MsgBox "I'm unlocked. Do your deed."
ActiveDocument.Protect wdAllowOnlyFormFields, True
MsgBox "I'm back in chains."
Else
MsgBox "I wasn't locked to start with"
End If
End Sub
 
W

WordWorker

Thank you so much, Greg. You are a job saver!


Greg Maxey said:
Sub OnExit()
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
MsgBox "I'm unlocked. Do your deed."
ActiveDocument.Protect wdAllowOnlyFormFields, True
MsgBox "I'm back in chains."
Else
MsgBox "I wasn't locked to start with"
End If
End Sub
 
W

WordWorker

My excitement jumped the gun. I forgot to mention that the document is
password protected. As such, when it gets to the "ActiveDocument.Unprotect"
line, it chokes. I tried putting in the password as the string is indicated
to be written (see below), but the Debugger doesn't like that either. What
am I missing? What am I doing wrong?

ActiveDocument.Unprotect(password)
 
G

Greg Maxey

Replace "password" with the real password:

Sub OnExit()
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="password"
MsgBox "I'm unlocked. Do your deed."
ActiveDocument.Protect wdAllowOnlyFormFields, True
MsgBox "I'm back in chains."
Else
MsgBox "I wasn't locked to start with"
End If
End Sub
 
G

Graham Mayor

You would need to re-apply the password when reprotecting:

Dim sPassword as string
sPassword = "password"

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=sPassword
End If

'Do your stuff then

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, _
NoReset:=True, _
Password:=sPassword
End If


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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Joined
Nov 20, 2009
Messages
5
Reaction score
0
A) Open document > Select edit menu > choose select all > then choose copy from edit menu.
Open new document > edit menu> paste.
Select tools menu> choose options> window opens with options. Select form different tabs the edit

tab> make sure that al desired boxes are selected.
Select save tab>choose and mark box>ask about properties
accept or Apply options and close.
Save new document different name. When saving it should ask if you want to save properties>

choose not save. Maybe it asks if you want to modify properties> choose yes> select box archive

amongst read only, hidden or archive.
If this does not work.

B)There are many 3rd party utilities which claim to reset forgotten word password:
The program that I recommend is the Word Password Recovery 5.0 It recovers/removes the "Password

to Open" and "Password to Edit" for you to view and edit the document freely.

http://www.recoverlostpassword.com/products/wordpasswordrecovery.html
 

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