View Single Post
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default

On Fri, 18 Feb 2005 14:01:01 -0800, martin
wrote:

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.)

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org