×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How to open a protected Word document?

How to open a protected Word document?

How to open a protected Word document?

(OP)
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?

RE: How to open a protected Word document?

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.

RE: How to open a protected Word document?

(OP)
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.

RE: How to open a protected Word document?

(OP)
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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources