Re: VB/Word - Making lines read only by Jezebel
Jezebel
Fri Aug 27 00:15:11 CDT 2004
"Phillip Wu" <pwu@qantas.com.au> wrote in message
news:943cec75.0408262059.5c089fb7@posting.google.com...
> Hi,
>
> I'm trying to write an Visual Basic application that starts Microsoft
> Word to allow a user to edit a text file.
>
> However the first line is a header and the last line is a trailer and
> I don't want the user to delete these lines. Also when the user exits
> from Word (closes the file or exits Word) I want the control to be
> returned to the VB application so that I can update the trailer.
>
> I am new to VB with Word so please bear with me. There are not many
> resources on the Web to assist.
>
> What I need to know is:
> 1) Is there an easy way to make the line read-only? Line in this case
> is the same as the Sentences object. If not would I have to trap all
> the insert/replace/delete events and beep if the user is on the first
> or last line?
You can break the document in three sections: header, body, trailer, and
then protect the first and last. Not fool-proof, but if you don't mind
having section breaks in the document, it might be sufficient. There's no
other way to make parts of a document read-only. Forget about trapping the
insert etc events. Alternatively, don't worry about it while the user is
editing but check, in the Document_BeforeSave event, whether the header and
trailer are as you need them to be and correct if necessary.
>
> 2) Is there some sample code showing how I can start Word in VB AND
> take back control when the user closes the file?
>
Use early binding. Declare your Word application reference 'with events' and
put the appropriate event code in your VB app. However 'take back control'
is a slightly dubious concept in an object-oriented language like VB. But at
least your app is notified that the user has closed with the document or
quit Word.