Unprotect document

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Is there a reported probelm with the Unprotect vba command? The following
code is from a recorded maco: (ok, it's silly because it locks and unlocks
the document in the same step, but I was experimenting).

ActiveDocument.Protect Password:="password", NoReset:=False, Type:= _
wdAllowOnlyComments, UseIRM:=False, EnforceStyleLock:=False
ActiveDocument.Unprotect

While recording, it produced the input box, requesting the password, as
expected. But when I go into vb editor an "Run" the routine, it produces the
message:

Runtime error '5485' The password is incorrect.

The input box never appeared requesting the password. Debug shows a problem
with "ActiveDocument.Unprotect" This code was written by the recorder!
 
Is there a reported probelm with the Unprotect vba command? The following
code is from a recorded maco: (ok, it's silly because it locks and unlocks
the document in the same step, but I was experimenting).

ActiveDocument.Protect Password:="password", NoReset:=False, Type:= _
wdAllowOnlyComments, UseIRM:=False, EnforceStyleLock:=False
ActiveDocument.Unprotect

While recording, it produced the input box, requesting the password, as
expected. But when I go into vb editor an "Run" the routine, it produces the
message:

Runtime error '5485' The password is incorrect.

The input box never appeared requesting the password. Debug shows a problem
with "ActiveDocument.Unprotect" This code was written by the recorder!

Just because a macro is recorded by the recorder does *not* mean that
it's correct or will work without errors. There are a number of cases
in which that is not true.

If you know that the document protection is passworded, you have to
edit the recorded macro to include the password in the Unprotect
command. The Help topic on that command includes this example:

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:=strPassword
End If

(You have to supply the value of the variable strPassword in some way,
either as a constant stored in the macro or by using an InputBox
statement to have the user type it in.)
 

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

Back
Top