Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Making Word Documents View/Print Only

Status
Not open for further replies.

jeffward

MIS
Jul 3, 2002
33
0
0
GB
I have an application that uses ole to generate word documents via a mail merge and at present the users can load the documents for checking before printing.

As a result on new regulations, I need to be able to stop the users from any form of editing i.e. save as, copy and paste into another word documents etc.

I have searched the web for the past couple of hours and have not found any decent solutions.

The best solution I can think of so far is to convert the word document to a pdf.

I beleive i will be able to do this using Ghostscript but I cant beleive there is not a better way to handle this problem!.
 
Uh, just to clarify - you should password protect the entire document as a form. If you password protect the document itself, unless you know the password, you can not even open it.

I am assuming that you want people to be able to read it.

If the document is generated, and you are not using other section breaks (i.e. there is only one section) just put this in the Document_Close event.

ActiveDocument.Protect Password:="whatever", NoReset:=False, Type:= _
wdAllowOnlyFormFields

That way anyone can read it, but can't do anything with it. Even if you do a Save As it will carry the protection over.

Gerry
 
Thanks Fumei, setting the protect form looks as if it will do what i want but the number of sections in the documents may vary.

Is it possible and does anyone have an example of how this can be done through code, i'm sure theres a nice simple protect all sections command!?
 
Thanks for your input but I have this working now.
 
No problem TriscuiT, I am using an Word protect function as suggested by Fumei, works even if there are multiple sections.

I can show you the code if you want but I am using an oracle forms application and the OLE functions are not as easy to read as say word basic!
 
Uh, all you have to do is, when you Protect Document for Forms, make sure all the sections are selected for protection. This should be the default, and:

Sub protectme()
ActiveDocument.Protect Password:="", NoReset:=False, Type:= _
wdAllowOnlyFormFields
End Sub

in most cases that should protect all sections. That is the default - all sections. However, if you really want to be absolutely certain:

Code:
Sub protectme2()
Dim var
Dim i As Integer
i = 1
On Error Resume Next
For var = 1 To ActiveDocument.Sections.Count
    ActiveDocument.Sections(i).ProtectedForForms = True
    i = i + 1
Next
' add password, left blank here
ActiveDocument.Protect Password:="", NoReset:=False, Type:= _
  wdAllowOnlyFormFields
End Sub

That explicitly protects all sections.


Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top