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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Two Word questions.

Status
Not open for further replies.

shannanl

IS-IT--Management
Apr 24, 2003
1,071
US
I am working on an application using vb.net. I open a word document, allow the user to type text and then save the document. The user can reopen and add text several times. At some point in the process, they save the document and it needs to be locked (read-only?) so no additional changes can be made. How do I programatically lock a document so that it is view or read only? The second question is that I am inserting some text in this document at the top and then the user types additional data. As it is now, the cursor is at the top left of the document. I would like the document started up with the cursor below the pre inserted text. How can I control where the cursor will be?

Thanks in advance for the help.

Shannan
 
As you ask in a VBA forum, here a VBA replies:
1) ActiveDocument.ReadOnly = True
2) Have a look at the Bookmark object.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The epitome of brevity, but indeed that is how you do it.

#2 - make a Bookmark at the location you want to start at - say name it "StartHere".

In the Document_Open event use:
Code:
Private Sub Document_Open()
    Selection.GoTo What:=wdGoToBookmark, Name:="StartHere"
End Sub

#1 -
How do I programatically lock a document so that it is view or read only?
This depends on precisely what it is you want to do.

PHV' code is actually incorrect. If you try to execute that instruction you will get an error. ActiveDocument.ReadOnly is, in fact....read only. You can not, within VBA, assign ReadOnly = True. Yes, within VBA, you can assign the file attribute to ReadOnly using FileSystemObject. You are talking about VB, so changing the file attributes should be easy.

So if you are talking about the file attribute ReadOnly, you need to change the attribute of the file. FSO will do that.

If you are talking about viewing and not allowing edits, you can use Protection for forms.

Gerry
My paintings and sculpture
 
OOps, sorry for the wrong info :~/
In VBA no need of the FSO:
SetAttr strFullName, GetAttr(strFullName) Or vbReadOnly

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top