Open File Error

D

Dianne Siebold

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
 
D

Dianne Siebold

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 :)
 
R

RWN

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

--
Regards;
Rob
------------------------------------------------------------------------
Dianne Siebold said:
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 :)
 

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