PC Review


Reply
Thread Tools Rate Thread

Check if a workbook is open on a network.

 
 
Spreadsheet Solutions
Guest
Posts: n/a
 
      6th Mar 2007
Dear all;

I need to check if someone on the network is using a workbook called "BRS".
How do I do that ?

I have this function (by Andy Pope), but can't get it to work.
'-----------------------------------------------------------------
Function IsNetworkFileOpen(Filename As String)
'-----------------------------------------------------------------
Dim nFile As Long

IsNetworkFileOpen = False

nFile = FreeFile()
On Error Resume Next
Open Filename For Input Lock Read Write As #nFile
If Err <> 0 Then
If Err.Number = 70 Then
IsNetworkFileOpen = True
Else
IsNetworkFileOpen = "No such file"
End If
End If
On Error GoTo 0
Close #nFile

End Function
'-----------------------------------------------------------------

Were does Workbooks("BRS.xls") comes into play ?


Many thanks beforehand.
--
--
Mark Rosenkrantz
--


 
Reply With Quote
 
 
 
 
Alan
Guest
Posts: n/a
 
      7th Mar 2007
Sub TestFileOpened()

' Test to see if the file is open.
If IsFileOpen("C:\Book2.xls") Then 'Change this to
network path: \\F:\Folder1\Folder2
' Display a message stating the file in use.
MsgBox "File already in use!"
'
' Add code here to handle case where file is open by another
' user.
'
Else
' Display a message stating the file is not in use.
MsgBox "File not in use!"
' Open the file in Microsoft Excel.
Workbooks.Open "C:\Book2.xls" 'Change this to
network path: \\F:\Folder1\Folder2

'
' Add code here to handle case where file is NOT open by another
' user.
'
End If


Copied from Microsoft's website, except for my two network remarks.

Regards,

Alan


"Spreadsheet Solutions" <(E-Mail Removed)> wrote in message
news:45edad6a$0$380$(E-Mail Removed)...
> Dear all;
>
> I need to check if someone on the network is using a workbook called
> "BRS".
> How do I do that ?
>
> I have this function (by Andy Pope), but can't get it to work.
> '-----------------------------------------------------------------
> Function IsNetworkFileOpen(Filename As String)
> '-----------------------------------------------------------------
> Dim nFile As Long
>
> IsNetworkFileOpen = False
>
> nFile = FreeFile()
> On Error Resume Next
> Open Filename For Input Lock Read Write As #nFile
> If Err <> 0 Then
> If Err.Number = 70 Then
> IsNetworkFileOpen = True
> Else
> IsNetworkFileOpen = "No such file"
> End If
> End If
> On Error GoTo 0
> Close #nFile
>
> End Function
> '-----------------------------------------------------------------
>
> Were does Workbooks("BRS.xls") comes into play ?
>
>
> Many thanks beforehand.
> --
> --
> Mark Rosenkrantz
> --
>
>



 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      7th Mar 2007
You call that function from another procedure with code such as

Dim IsOpen As Boolean
IsOpen = IsNetworkFileOpen(Workbooks("BRS.xls").FullName)
If IsOpen = True Then
' do something - file is open by another process or user
Else
' do something else - file is not open
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"Spreadsheet Solutions" <(E-Mail Removed)> wrote in message
news:45edad6a$0$380$(E-Mail Removed)...
> Dear all;
>
> I need to check if someone on the network is using a workbook called
> "BRS".
> How do I do that ?
>
> I have this function (by Andy Pope), but can't get it to work.
> '-----------------------------------------------------------------
> Function IsNetworkFileOpen(Filename As String)
> '-----------------------------------------------------------------
> Dim nFile As Long
>
> IsNetworkFileOpen = False
>
> nFile = FreeFile()
> On Error Resume Next
> Open Filename For Input Lock Read Write As #nFile
> If Err <> 0 Then
> If Err.Number = 70 Then
> IsNetworkFileOpen = True
> Else
> IsNetworkFileOpen = "No such file"
> End If
> End If
> On Error GoTo 0
> Close #nFile
>
> End Function
> '-----------------------------------------------------------------
>
> Were does Workbooks("BRS.xls") comes into play ?
>
>
> Many thanks beforehand.
> --
> --
> Mark Rosenkrantz
> --
>
>



 
Reply With Quote
 
Spreadsheet Solutions
Guest
Posts: n/a
 
      7th Mar 2007
Chip;

Thanks for the feedback.
I overlooked the reference to the correct path.
It works fine now !!

--
--
Mark Rosenkrantz
--
Spreadsheet Solutions
Witkopeend 24
1423 SN, Uithoorn
Netherlands
--
W: www.rosenkrantz.nl
E: (E-Mail Removed)
--
"Chip Pearson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You call that function from another procedure with code such as
>
> Dim IsOpen As Boolean
> IsOpen = IsNetworkFileOpen(Workbooks("BRS.xls").FullName)
> If IsOpen = True Then
> ' do something - file is open by another process or user
> Else
> ' do something else - file is not open
> End If
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email address is on the web site)
>
> "Spreadsheet Solutions" <(E-Mail Removed)> wrote in message
> news:45edad6a$0$380$(E-Mail Removed)...
>> Dear all;
>>
>> I need to check if someone on the network is using a workbook called
>> "BRS".
>> How do I do that ?
>>
>> I have this function (by Andy Pope), but can't get it to work.
>> '-----------------------------------------------------------------
>> Function IsNetworkFileOpen(Filename As String)
>> '-----------------------------------------------------------------
>> Dim nFile As Long
>>
>> IsNetworkFileOpen = False
>>
>> nFile = FreeFile()
>> On Error Resume Next
>> Open Filename For Input Lock Read Write As #nFile
>> If Err <> 0 Then
>> If Err.Number = 70 Then
>> IsNetworkFileOpen = True
>> Else
>> IsNetworkFileOpen = "No such file"
>> End If
>> End If
>> On Error GoTo 0
>> Close #nFile
>>
>> End Function
>> '-----------------------------------------------------------------
>>
>> Were does Workbooks("BRS.xls") comes into play ?
>>
>>
>> Many thanks beforehand.
>> --
>> --
>> Mark Rosenkrantz
>> --
>>
>>

>
>



 
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
Check if workbook is open... John Microsoft Excel Programming 2 10th Jun 2008 10:04 PM
Check for open workbook =?Utf-8?B?T2xkamF5?= Microsoft Excel Programming 3 17th Apr 2008 11:09 AM
If Then to check if a workbook is open =?Utf-8?B?U2hhd24=?= Microsoft Excel Misc 5 25th Nov 2006 04:29 PM
Check if workbook is already open... Cumberland Microsoft Excel Programming 1 22nd Aug 2006 09:16 AM
How check if workbook open? =?Utf-8?B?SWFuIEVsbGlvdHQ=?= Microsoft Excel Programming 7 14th Apr 2006 08:54 PM


Features
 

Advertising
 

Newsgroups
 


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