View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
March March is offline
external usenet poster
 
Posts: 34
Default How to wirte vba to find the opening file?

I will let you know how it work.


Thanks

"Simon Lloyd" wrote:


Try this, created by Bob Phillips:

Code:
--------------------
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

--------------------
March;185826 Wrote:
I mean the file already open, not the open file dialogue box.

I want to check, if the file opens or not?




"Simon Lloyd" wrote:


Do you mean the open file dialogue box or do you mean the

Workbook_Open
event?March;185764 Wrote:
Hello All,

Please give me suggestion.

How to wirte vba to find the opening file?


Thanks,

March


--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' ('The Code Cage' (http://www.thecodecage.com))

------------------------------------------------------------------------
Simon Lloyd's Profile: 'The Code Cage Forums - View Profile: Simon

Lloyd' (http://www.thecodecage.com/forumz/member.php?userid=1)
View this thread: 'How to wirte vba to find the opening file? - The

Code Cage Forums'
(http://www.thecodecage.com/forumz/sh...ad.php?t=51302)




--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=51302