Graham
Wed Jan 09 04:26:30 PST 2008
Strictly speaking, if the document is already protected it doesn't need
protecting but
Sub ProtectMyForm()
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
NoReset:=True, Password:=""
Else
MsgBox "Document is already protected"
End If
End Sub
will do the trick. Leave out the
Else
MsgBox "Document is already protected"
if you prefer. NOTE that your macro name ProtectForm is the name of the
in-built function for protecting forms and will interfere with the normal
use of that function.
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
My web site www.gmayor.com
Word MVP web site
http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
hermithead wrote:
> The code works fine
>
> Sub ProtectForm()
>
> ActiveDocument.Protect _
> Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
>
> End Sub
>
>
> but if the macrobutton is clicked again then the following error
> displays:
> Run time error 4605 This Project method or property is not available
> because the document is already protected.
>
>
> On Jan 9, 5:38 pm, "Graham Mayor" <gma...@REMOVETHISmvps.org> wrote:
>> ActiveDocument.Protect _
>> Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
>>
>> --
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>> Graham Mayor - Word MVP
>>
>> My web sitewww.gmayor.com
>> Word MVP web site
http://word.mvps.org
>> <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
>>
>> hermithead wrote:
>>> Hi, How do you make the following code Protect only? This code will
>>> protect an unprotected form AND unprotect a protected form. I just
>>> need it to Protect.
>>
>>> Sub ProtectForm()
>>
>>> If ActiveDocument.ProtectionType = wdNoProtection Then
>>> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _
>>> NoReset:=True
>>> Else
>>> ActiveDocument.Unprotect Password:=""
>>> End If
>>
>>> End Sub