In my limited testing, the following code from Ivan Moala will tell you if a
file is open in any instance of Excel. It will not tell you which instance
it is open in...
'----------------------------------------
'// Ivan F Moala
'//
http://www.xcelfiles.com
Sub TestVBA()
If IsFileOpen("C:\Data.xls") Then
MsgBox "File is open"
Else
MsgBox "File is not open"
End If
End Sub
Function IsFileOpen(strFileName As String) As Boolean
'// VBA version to check if File is Open
'// We can use this for ANY FILE not just Excel!
'// Error is generated if you try
'// opening a File for ReadWrite lock >> MUST BE OPEN!
Dim hdlFile As Long
On Error GoTo FileIsOpen:
hdlFile = FreeFile
Open strFileName For Random Lock Read Write As hdlFile
IsFileOpen = False
Close hdlFile
Exit Function
FileIsOpen:
'// Someone has it open!
IsFileOpen = True
Close #1
End Function
'-----------------------------------------------------
Regards,
Jim Cone
San Francisco, CA
'****************************************