Determining if a file is open

N

Neil

I am trying to determine if a Word doc is open, because I have a process
that looks to open it, save it in a different format, and then move on to
another doc.

I tried using the command:

If Dir(strFilePath & "~$" & strfilename, vbHidden) <> "" Then
'Skip file
End if

to use the "~$" file to determine if it's open. This worked fine on my PC.
However, when I tried it on the network, it didn't work.

I need to be able to determine if a file is open, either by using Dir(), or
by using some method within Word. Since the files are open across a network,
I can't check the open documents in my copy of Word. Any ideas? Using Word
2000.

Thanks!

Neil
 
J

jan

Neil,

This is a way doing it:

Function DocIsOpen(strFullName As String)
Dim wrdDoc As Word.Document
Dim blnResult As Boolean
For Each wrdDoc In Word.Documents
If StrComp(wrdDoc.FullName, strFullName, vbTextCompare) = 0 Then
blnResult = True
Exit For
End If
Next
DocIsOpen = blnResult
End Function

You can use this function in this way:

docisopen("D:\Data\Discussieforum\Test\test.doc")

so use the fullname.


Jan
 
N

Neil

As I noted in my message, I am doing this across a network, so checking
which documents are open in my instance of Word doesn't do me any good. I
need to know if the document is open, period, by anyone on the network, not
just by me.
 
N

Neil

Thanks, Shauna. That would work. Only one thing I failed to mention
previously: this process will be running nightly on my development machine,
and on that machine I have error handling turned off. So that means the
process would break each time a file's not found.

I suppose I can turn error handling on at the beginning of the process and
then off again at the end (which would be OK as long as it didn't crash in
the middle). So, if I have to, I'll do that. Still, a solution that didn't
require error handling to be on would be better still.

Any idea why my original Dir() solution worked on my local machine to find
the ~$ file, but didn't work across the network?

Thanks!

Neil
 

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