View Full Version : [SOLVED:] Unprotect a document with a macro?
phill952000
12-05-2008, 06:49 AM
HI,
i am wondering if it is possible to create a macro that unprotects a protected document?
i understand that it is not possible to do this using the record new macro tool and simply clicking on it and saving the macro but i am wo9ndering if there is any code that can be manually put in to achieve this?
regards
lucas
12-05-2008, 08:11 AM
ActiveDocument.Unprotect Password:="pwd"
phill952000
12-05-2008, 08:46 AM
thanks alot worked a treat
:hi:
phill952000
12-05-2008, 08:56 AM
another question,
is there any way to say if the document is protected, unprotected it, then if the document is unprotected then ignore the unprotec piece of code.
my situation is i have a print macro that allows me to print 2 copies of the same page in word. but my word documents are protected when i first open them.
what i do is, i open the word document and enter the relevant information and then click the print macro which prints the document twice and unprotects the document.
then i change a piece of information and want to print it again using the same macro but this time ignoring the unprotecting piece of code that you gave me (which is spot on by the way) because it throws an error which i understand.
i hope you understand my situation
cheers
lucas
12-05-2008, 09:26 AM
Like this:
Sub leaveunprotected()
If ActiveDocument.ProtectionType = wdNoProtection Then
MsgBox "test" 'your code here
Else
ActiveDocument.Unprotect Password:="pwd"
End If
End Sub
lucas
12-05-2008, 09:30 AM
This may be better:
Sub leaveunprotected()
If ActiveDocument.ProtectionType = wdNoProtection Then
Else
ActiveDocument.Unprotect Password:="pwd"
End If
MsgBox "test" 'your code here
End Sub
phill952000
12-05-2008, 09:30 AM
much appriciated,
works a treat,
is there any way to not have the message box and to skip this part and just go ahead and print the two documents?
regards
lucas
12-05-2008, 09:32 AM
try replacing the msgbox code in post #7 with your print code....
If that don't work maybe you could post the document....
phill952000
12-05-2008, 09:38 AM
all sorted,
the second code you sent i just deleted the message box part and it does exactally what i want
many thanks again
lucas
12-05-2008, 09:46 AM
Good deal Phill, be sure to mark your thread solved using thread tools at the top of the page.
That way others looking to help won't needlessly visit the page.
phill952000
12-05-2008, 09:49 AM
thanks for the tip
This macro worked great for me as I want to be able to provide clients with the option of unprotecting a form should they need to make changes to contract terms. However, how do you prevent them from double clicking on the command button to see the underlying code, where the actual password is typed? Definitely don't want them to know the actual password. Thanks.
Hi -
In addition to my question above, does anyone have code that will not only unprotect the document, but ''re-protect'' it for tracked changes mode only? While I want to be client friendly and allow clients to make changes to terms, I also want the changes to be visible in tracked changes. Unfortunately, some clients have been known to sneak in changes and then sign the document without having us review their changes.
Since Word cannot allow two forms of a protection in a document, maybe there is code to allow this. Thank you.
fumei
05-21-2010, 11:13 AM
True, you can not set two types of protection.
ActiveDocument.Protect(wdAllowOnlyRevisions) allows...only revisions.
If you want to have them be able to make changes, then you can NOT have it protected for forms, and vice versa.
You can switch between the protection types though. So you could turn OFF protection for forms, then turn ON protection for revisions.
"However, how do you prevent them from double clicking on the command button to see the underlying code, where the actual password is typed? "
I am not following. Do you mean going into the Visual Basic Editor and looking at the code (assuming the turning off protection code has a password)? You can't. Once you turn off protection, it is turned off.
"I want to be able to provide clients with the option of unprotecting a form should they need to make changes to contract terms"
In which case...what is the point of having protection in the first place???
Thank you. How do you allow a user to switch from form mode to revision mode?
The reason for starting in forms mode is to make completion easier for my company's users (and to prevent our teams from making revisions). The reason for wanting to allow revisions mode is to allow our clients to make changes. Most clients do not like to receive a form that they cannot edit, and they then have to come back and ask for an unprotected form. I'm trying to balance controls with flexibility. Thanks.
fumei
05-21-2010, 11:43 AM
With ActiveDocument
.Unprotect "xxxxx"
.Protect wdAllowOnlyRevisions, , Password:="xxxxx"
End With
turns OFF whatever protection type it was, and turns ON protection for revisions.
"I'm trying to balance controls with flexibility."
In a way, you have an impossible task.
Thank you Gerry, this has been a helpful solution.
When you're dealing with contracts in the industry we are in, we have to have both controls and flexibility. Unfortunately we don't have a fancy contract management system with sophisticated document authoring and creation capabilities. Thanks again.
fumei
05-21-2010, 12:13 PM
All I can say is that I hope you never, ever, open documents from email attachments.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.