View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
thomas thomas is offline
external usenet poster
 
Posts: 12
Default Re : Excel 2003 - VBA File already opened

thanks but does it work whatever the instance of Excel?


"Spreadsheet Solutions" a écrit dans le message de
groupe de discussion : ...
This might be one solution.

Function IsFileOpen(FileName As String)
Dim iFilenum As Long
Dim iErr As Long

On Error Resume Next
iFilenum = FreeFile()
Open FileName For Input Lock Read As #iFilenum
Close iFilenum
iErr = Err
On Error Goto 0

Select Case iErr
Case 0: IsFileOpen = False
Case 70: IsFileOpen = True
Case Else: Error iErr
End Select

End Function

Sub test()
If Not IsFileOpen("C:\MyTest\volker2.xls") Then
Workbooks.Open "C:\MyTest\volker2.xls"
End If
End Sub
---

More, or other : http://www.cpearson.com/Excel/ISFILEOPEN.ASPX


--
Regards;
Mark Rosenkrantz
--
Spreadsheet Solutions
Uithoorn
Netherlands - Those who live some 18 feet below sea level
--
E:
W:
www.spreadsheetsolutions.nl
--
"thomas" <nomail wrote in message
...
Hello,

I want to open an Excel file through VBA and i first test if it's already
opened or not. If it's already opened i just reactivate it.

My problem is that sometimes the file is re-opened because it's already
opened but in an other instance of Excel.

How can i check all the instances of Excel?

Thanks