Automate Word & open Doc in Read-Only mode

A

Adrian

Hi,

I am using c# to auotmate Word 2000. The task involves
opening a Document and creating a print file from that
document. However, if another user already has the
document open, a dialog from Word stating "xyz.doc is
locked for editing" etc. is produced. I am forced to
manually click on the Read Only button displayed in the
dialog while the c# program execution is halted. I need
this process to operate unattended & cannot be clicking
this dialog whenever it appears.

The relevant code snippet to open the doc is:
ObjWord.Documents.Open(ref filename, ref
confirmConversions, ref readOnly, ref addToRecentFiles,
ref passwordDocument, ref passwordTemplate, ref revert,
ref writePasswordDocument, ref writePasswordTemplate, ref
format, ref encoding, ref visible);

The "ref readOnly" parameter has been assigned using:
Object readOnly = true;

but does not appear to force the document to be opened in
read-only mode.

Thankyou for any help.

Adrian.
 
C

Cindy M -WordMVP-

Hi Adrian,

Word was not designed to be run unattended, or on a server,
so what you're looking for isn't supported. The closest you
can get is to check the file BEFORE you try opening it to
find out if it's locked (Try - Catch opening it as you
would a plain text file, for instance). Then you could try
copying it to another (temp) location and open it from
there.
I am using c# to auotmate Word 2000. The task involves
opening a Document and creating a print file from that
document. However, if another user already has the
document open, a dialog from Word stating "xyz.doc is
locked for editing" etc. is produced. I am forced to
manually click on the Read Only button displayed in the
dialog while the c# program execution is halted. I need
this process to operate unattended & cannot be clicking
this dialog whenever it appears.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
G

Guest

Thankyou Cindy,

Your advice worked great when I wrote my solution as an
application automating Word.

I found though, that Word would not print the document
when I converted the app to a service. The service
reports the error "Server execution failed". Is there a
method that can automate Word to run as an application in
the foreground rather than a task (I assume this is what
is happening since Word appears as a process in the Task
Scheduler and seems to hang)?

Many thanks,
Adrian Smith
 
C

Cindy M -WordMVP-

I found though, that Word would not print the document
when I converted the app to a service. The service
reports the error "Server execution failed". Is there a
method that can automate Word to run as an application in
the foreground rather than a task (I assume this is what
is happening since Word appears as a process in the Task
Scheduler and seems to hang)?
I'm afraid I have only a very vague idea what a "service"
is...? Service as in "web service"? You may need to ask this
in a .NET group, as I suspect the problem may generally
apply to (COM)applications designed to run in the interface.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun
8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top