PC Review


Reply
Thread Tools Rate Thread

Check if a file is already open

 
 
Cresta
Guest
Posts: n/a
 
      1st Apr 2009
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 With Quote
 
 
 
 
RB Smissaert
Guest
Posts: n/a
 
      1st Apr 2009
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" <(E-Mail Removed)> wrote in message
news:5F62903B-17B5-4849-9C8F-(E-Mail Removed)...
> 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 With Quote
 
Cresta
Guest
Posts: n/a
 
      1st Apr 2009
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" <(E-Mail Removed)> wrote in message
> news:5F62903B-17B5-4849-9C8F-(E-Mail Removed)...
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a way to check if file is already open? Kimmo Laine Microsoft C# .NET 2 31st May 2007 06:38 PM
Check to see if a file is already open =?Utf-8?B?SmFzb24gWmlzY2hrZQ==?= Microsoft Excel Programming 2 30th Jun 2006 08:56 AM
How to check if file is OPEN Alex Simic Microsoft VB .NET 4 30th Nov 2005 04:36 PM
vba to check presence of file and open/not open fLiPMoD£ Microsoft Excel Discussion 2 28th Apr 2005 08:14 PM
Check if file is open Randy Microsoft C# .NET 1 23rd Mar 2004 09:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:29 AM.