Protect word document function is not working

Set objWordApp = CreateObject(“Word.Application”) 'Create Word objectSet objWordDoc = objWordApp.activedocument

objWordDoc.Unprotect(“password”)

objWordDoc.FormFields(“fieldname”).Enabled=True

'Till here code works fine.

objWordDoc.Protect(“password”)

In the above line, I get type mismatch error though I pass other parameters for protect function.

Can anyone help me on this please?

Just want to know how to protect word document using lotus script.

Thanks in advance.

Subject: Protect word document function is not working.

This is not really the place to ask about Word programming, however…

This is from Word 2002 version’s help. The command needs more than just a password.

Protect Method

See Also Applies To Example Specifics

Protects the specified document from changes. When a document is protected, the user can make only limited changes, such as adding annotations, making revisions, or completing a form.

Note If the document is already protected when you use this method, an error occurs.

expression.Protect(Type, NoReset, Password)

expression Required. An expression that returns one of the objects in the Applies To list.

Type Required The protection type for the specified document. WdProtectionType.

WdProtectionType can be one of these WdProtectionType constants.

wdAllowOnlyComments

wdAllowOnlyFormFields

wdAllowOnlyRevisions

wdNoProtection

NoReset Optional Variant. False to reset form fields to their default values. True to retain the current form field values if the specified document is protected. If Type isn’t wdAllowOnlyFormFields, the NoReset argument is ignored.

Password Optional Variant. The password required to “unprotect” the specified document.

Example

This example protects the active document for forms without resetting the contents of the form fields.

If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If

This example protects Monthly Report.doc so that only comments can be added to it. The password “free” is required to unprotect the document.

Set myDoc = Documents(“Monthly Report.doc”)
myDoc.Protect Type:=wdAllowOnlyComments, Password:=“free”

Subject: RE: Protect word document function is not working.

I need the code for Lotus Notes. Please refer to pasted code. I am using the same method mentioned by you but getting error. (Type Mismatch).

Can you please send me lotus code?

Thanks in advance.

Subject: RE: Protect word document function is not working.

By calling “Set objWordDoc = objWordApp.activedocument” you are actually using the MS Word program. I know you are creating your code in Notes, but you are calling Word functions, and you’ll need to understand them for the version of Word installed on your machine !

On My machine, I have MS Word 2002. In that version, the Protect property of a WordDocument needs 3 parameters, and you were only passing it one.

The 3 parameters needed are :

What type of protection are you trying to apply to the document ? (Word can protect it in one of 3 ways)

A NoReset flag, only needed if you are protecting for forms

The password

Since you were getting an error message with only the password, I’m guessing that you need to provide more parameters.

You may try objWordDoc.Protect(0,false,“password”) but I don’t know if that will work for you.

Subject: RE: Protect word document function is not working.

Not all our users had the same version of MSWord so our script had to check:

If (Wordversie = “1”) Then 'Protect mode msword 2003

oMSWord.ActiveDocument.Protect 3, True, UNID

Elseif (Wordversie = “9”) Then 'Protect mode msword 2000

oMSWord.ActiveDocument.Protect 1

End If