N
njmike
I've had a macro to password protect documents for a while and it works
fine - except for one issue I just found. When the macro is run on a
document that was once protected for certain sections, only those
sections are protected. The only way I can protect all the sections is
to manually protect the form and individually check all of the sections
in the options. My current code is as follows:
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Password:="mypassword", NoReset:=False,
Type:=wdAllowOnlyFormFields
End If
So I was playing around to see how a macro would record if I did only
want to protect certain sections. By doing so, I noticed it has a new
line for each section. So if a document had 5 sections, and I wanted
to ensure all of the sections were protected, I would need the
following code:
On Error Resume Next
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = True
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Sections(4).ProtectedForForms = True
ActiveDocument.Sections(5).ProtectedForForms = True
ActiveDocument.Protect Password:="mypassword", NoReset:=False,
Type:=wdAllowOnlyFormFields
The "On Error Resume Next" command, btw, is needed to make sure I don't
get an error if the document has less than 5 sections.
I've done plenty of searching, but I can't find any code that is
simpler. I wanted to do something like
ActiveDocument.AllSections.ProtectedForForms = True
or
ActiveDocument.Sections(1 - 5).ProtectedForForms = True
but nothing seems to work. Is there a simpler way to write this macro?
Thanks in advance,
- Mike
fine - except for one issue I just found. When the macro is run on a
document that was once protected for certain sections, only those
sections are protected. The only way I can protect all the sections is
to manually protect the form and individually check all of the sections
in the options. My current code is as follows:
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Password:="mypassword", NoReset:=False,
Type:=wdAllowOnlyFormFields
End If
So I was playing around to see how a macro would record if I did only
want to protect certain sections. By doing so, I noticed it has a new
line for each section. So if a document had 5 sections, and I wanted
to ensure all of the sections were protected, I would need the
following code:
On Error Resume Next
ActiveDocument.Sections(1).ProtectedForForms = True
ActiveDocument.Sections(2).ProtectedForForms = True
ActiveDocument.Sections(3).ProtectedForForms = True
ActiveDocument.Sections(4).ProtectedForForms = True
ActiveDocument.Sections(5).ProtectedForForms = True
ActiveDocument.Protect Password:="mypassword", NoReset:=False,
Type:=wdAllowOnlyFormFields
The "On Error Resume Next" command, btw, is needed to make sure I don't
get an error if the document has less than 5 sections.
I've done plenty of searching, but I can't find any code that is
simpler. I wanted to do something like
ActiveDocument.AllSections.ProtectedForForms = True
or
ActiveDocument.Sections(1 - 5).ProtectedForForms = True
but nothing seems to work. Is there a simpler way to write this macro?
Thanks in advance,
- Mike