Change Headers and Footers in a document protected for forms

Article contributed by Bill Coan

If you want to write code that changes the Headers and/or Footers in a document protected for forms, you need to wrap your code in an unprotect/reprotect sandwich like so:

'First unprotect the Form
ActiveDocument.Unprotect Password:="Mypassword"

'Add your code that operates on the Header or Footer here,
'for example:
ActiveDocument.Sections(1).Headers(1).Range.Text = "Hello"

'Then reprotect the form
ActiveDocument.Protect Password:="Mypassword", NoReset:=True, Type:= _
        wdAllowOnlyFormFields