VBA code in word 2007 for "protect" and "unprotect" buttons

I want to put two buttons inside a word document (word 2007):  Protect and Unprotect.  It's actually a form.  How do I write the code for those two buttons?  I mean, what is the actual code I need to write?
 

Question Info


Last updated May 2, 2018 Views 518 Applies to:
Answer
Answer

It depends on what type of protection you want to apply.  Here is one example.

Sub Prot()
'A basic Word macro coded by Greg Maxey
ActiveDocument.Protect wdAllowOnlyFormFields, True
End Sub
Sub UnProt()
'A basic Word macro coded by Greg Maxey
If ActiveDocument.ProtectionType <> wdNoProtection Then
  ActiveDocument.Unprotect
End If
End Sub

If you are wanting the Classic Formfield tools back then see:

http://gregmaxey.mvps.org/word_tip_pages/add_classic_form_controls.html

Best Regards,
Greg Maxey

For more help with Word visit:
http://gregmaxey.com/word_tips.html

Did this solve your problem?

Sorry this didn't help.

Great! Thanks for marking this as the answer.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this response?

Thanks for your feedback.