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!

Locking Word

Status
Not open for further replies.

Kreiss

Programmer
Oct 8, 2003
48
0
0
US
I have an application that opens Word 97. I am trying to lock Word so users can't make any chages to the document. Any suggestions on locking the document so changes can't be made?

Thanks.
 
You could set the file attributes of the document to read-only. You could set a password for making changes but not viewing (I know this can be done in 2000 but am not sure about 97). Depending on the OS and network environment you could set permissions at the OS/Network level. All can be done from within your app too. You might want to be a little more descriptive as to what you really want to do. If you just don't want anybody to be able to modify the document except via your app then setting OS/Network permissions are your best bet as if you just set it to read-only they could always change that if they new how.
 
Here is a sample of the code I'm using. I'm not for sure how to set it to read only from within the application. I need someway to unlock it so I can add the information to the document then lock it once the Word document is open so changes can't be made.

Thanks in advace...

On Error GoTo ErrorHandler
Dim NumRows As Integer
Dim myTable As Table
Dim X As Integer
Dim WordObject As Object
Set WordObject = CreateObject("Word.application")

MousePointer = vbHourglass

With WordObject
.Documents.Open (ReportDir + "\Document")
.Visible = True

.ActiveDocument.Bookmarks("txtPrintDate").Select
.Selection.Text = Format(Date, "mm/dd/yyyy")
 
What about setting Object to Word.document?
In that case you have Protect method and you can easily protect the document.

Here's the code (Go to References and check Microsoft Word x Object library (where X is the version)):

Dim doc As New Word.Document
Dim wApp As New Word.Application

Set doc = wApp.Documents.Open("sampledocument")
'protect with maximum protection
doc.Protect wdAllowOnlyReading, , "myPassword"

---------------------------------
LendPoint Software
 
First two lines should look like this:
Just add the Word.document object and you will get the "Protect" method.

Sorry for the mistake :)



---------------------------------
LendPoint Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top