Hi Serge,
One way is to try to gain exclusive access yourself. If you succeed, no
other process has the file open. Air code:
Function IsFileAvailable(FileSpec as String) As Boolean
If Len(Dir(FileSpec)) > 0 Then 'make sure file exists
lngFileNum = FreeFile()
On Error Resume Next
Open FileSpec For Input Lock Read Write As #lngFileNum
If Err.Number = 0 Then 'file opened successfully
IsFileAvailable = True
Close #lngFileNum
Else 'file could not be opened
IsFileAvailable = False
End If
On Error GoTo 0
End If
End Function
As well as checking that the file exists, you may also want to check the
permissions on it; if you don't, the function will misleadingly return
True when the file isn't actually open but the current user doesn't have
permission to open it.
Also, remember that the fact that a file is "open" in some application
does not necessarily mean that the file is open from the operating
system's point of view. When Notepad (and many others) "open" a text
file, for instance, they open the actual disk file, read its contents
into memory, and immediately close it. The actual editing is done in
memory and the file on disk isn't touched until you save your work. As
far as I know, however, Word and Excel keep their files open.