#1   Report Post  
martin
 
Posts: n/a
Default Unprotect document

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!


  #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
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you save individual document pages as seperate word files? John Calligy Mailmerge 2 April 12th 05 09:14 AM
How do I unprotect a document if I can't press the unprotect butt. ogrundmann Microsoft Word Help 4 February 15th 05 09:31 AM
unprotect document option is grayed out - cannot unprotect? Jon R Microsoft Word Help 2 February 11th 05 10:46 AM
Newbie document question please Dudley Henriques New Users 4 January 9th 05 08:38 PM
Document object in protected form Bruce Tables 2 December 6th 04 07:09 PM


All times are GMT +1. The time now is 08:48 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"