Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to open a protected Word document?

Status
Not open for further replies.

cll

Electrical
Jun 11, 2002
22
DK
I have written a macro in Excel to open a word-document as template, write some data from excel to word and print (the excel-user do not se word). Now I want to protect my word-document-template from being changed. But then I have problems with the automatic sequence, bacause it stops by asking for password/readonly.
The macro for opening word is:

Set wrd = CreateObject("Word.Application")
wrd.Documents.Add Template:="Dir\0274_0.doc",
NewTemplate:=False

Can anybody help this little task?
 
Replies continue below

Recommended for you

I am not sure I completely understand what you want, so this may be off course a bit.

Instead of protecting the template, can you just protect the new document once it's created? This can be accomplished during the SaveAs method. If not, here are a couple of procedural work-arounds:

1. Copy the template file to a temporary file
Open the temp file template passing the pwd
Save and Close the temporary template
Create a new doc based on that template
Delete the temporary template

2. Open the template with the pwd
Save and Close the template
Create your new Doc
Open the template again
SaveAs with the pwd
DimensionalSolutions@Core.com
While I welcome e-mail messages, please post all thread activity in these forums for the benefit of all members.
 
Hi dsi - thanks for promt answer - it´s always a problem shortly to describe a project, and your solution will do fine, but I have no need to saveas and the other workarounds.
I only grab the template, fill it with data from excel, print it out and leave it (as it was) for the next to do the same. The excel worksheet is used to store the data (protected). I want to protect the template from inadvertently changes, because it is located for network use.
 
From Tek-tips I got this answer:

"Have you tried the Protect Method? From VBA Help:

Protect Method


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.

Syntax

expression.Protect(Type, NoReset, Password)

expression Required. An expression that returns a Document object.

Type Required Long. The protection type for the specified document. Can be one of the following WdProtectionType constants: wdAllowOnlyComments, wdAllowOnlyFormFields, wdAllowOnlyRevisions, or 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.

Since you say it's a template, you may have to protect the New TemplateDocument when it's created, but worth a shot! And I think you have to use the Add method with a template. I think by using Open it opens the actual template instead of creating a new document based on the template."

And it works out fine combined with the UnProtect method.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top