I have a DLL that opens a template document, creates a data document and then does a mail merge with output going to a new document. In the code below, when it tries to open the file with the merge fields and another user has it open, the user gets a "File In Use" dialog with the buttons Read Only (to open the file in read-only mode), Notify and Cancel. If the user clicks the Read Only button, it opens the file and everything works fine. If the user clicks the Cancel button it goes back to the code and returns error number 4198 "Command Failed."

I have tried using different flags on the Open (ReadOnly:=True) but it always displays the File In Use dialog. Is there a way I can tell if another user has the file open before I open it? I've looked on MSDN but I've only found how to tell if the file is open on the current machine.

Thanks for any assistance.

If mTemplateFile <> "" Then
Set mWord = CreateObject("Word.Application")
mWord.Visible = True
Set mWordMergeDoc = mWord.Documents.Open(mTemplateFile) <== shows the File In Use dialog
DoEvents
mWordMergeDoc.Select

Re: Open File Error by Helmut

Helmut
Tue Jan 06 04:09:26 CST 2004

Hi Dianne,
see
http://www.mvps.org/word/FAQs/MacrosVBA/CheckIfFileOpen.htm
Article contributed by Jonathan West
Greetings from Bavaria, Germany
Helmut Weber
"red.sys" & chr$(64) & "t-online.de"
Word 97, W98


Re: Open File Error by dsiebold

dsiebold
Tue Jan 06 11:21:36 CST 2004

Thanks, I'll try that out. I thought Word would provide some way to do this because it can tell you who has the file open :)

Re: Open File Error by RWN

RWN
Wed Jan 07 22:27:19 CST 2004

Not an expert, but;
Can you not just make the file shareable?

--
Regards;
Rob
------------------------------------------------------------------------
"Dianne Siebold" <dsiebold@earthlink.net> wrote in message
news:231F9642-7102-4B5D-9938-50C41214F529@microsoft.com...
> Thanks, I'll try that out. I thought Word would provide some way to
do this because it can tell you who has the file open :)