Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Check if a file is already open

Hello all
Is there any way to check if a file is already open by another user before
trying to open it.

If "Filename is open" = true then
abort procedure
else
Workbooks.Open Filename....
end if

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Check if a file is already open

Try this function:

Function FileIsOpen(strFile As String) As Boolean

Dim hFile As Long

On Error GoTo OpenError

hFile = FreeFile

Open strFile For Input Lock Read As #hFile
Close #hFile

Exit Function
OpenError:

FileIsOpen = Err.Number = 70

End Function


RBS


"Cresta" wrote in message
...
Hello all
Is there any way to check if a file is already open by another user before
trying to open it.

If "Filename is open" = true then
abort procedure
else
Workbooks.Open Filename....
end if

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 76
Default Check if a file is already open

Thanks
That worked a treat


"RB Smissaert" wrote:

Try this function:

Function FileIsOpen(strFile As String) As Boolean

Dim hFile As Long

On Error GoTo OpenError

hFile = FreeFile

Open strFile For Input Lock Read As #hFile
Close #hFile

Exit Function
OpenError:

FileIsOpen = Err.Number = 70

End Function


RBS


"Cresta" wrote in message
...
Hello all
Is there any way to check if a file is already open by another user before
trying to open it.

If "Filename is open" = true then
abort procedure
else
Workbooks.Open Filename....
end if

Thanks



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check if mdb file is open K[_2_] Excel Programming 2 December 24th 08 11:23 AM
check if file is already open mohavv Excel Discussion (Misc queries) 1 October 15th 07 12:08 AM
Check to see if a file is already open Jason Zischke Excel Programming 2 June 30th 06 08:56 AM
check if a file is open C[_4_] Excel Programming 6 March 31st 06 03:28 PM
check if file already is open Mats Nilsson Excel Programming 2 September 12th 05 09:30 AM


All times are GMT +1. The time now is 09:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"