PC Review


Reply
Thread Tools Rate Thread

Determine if a shared workbook is open

 
 
Mark Lincoln
Guest
Posts: n/a
 
      12th Feb 2008
Is there a way to determine if a shared workbook on a (Novell NetWare)
network drive is in use? I need to be able to replace a locked-down
shared workbook (for viewing by Those Who Should Not Make Changes)
with an updated copy produced from a non-shared Master file. I use a
separate workbook (I have my reasons) to open the Master file, save it
as an intermediate file, lock all its cells, protect all its sheets,
and save the resulting file in place of the old shared workbook.
Trying to save the file when someone has the old shared workbook open
will actually work, but not without some problems. So I don't want
the update code to run if either file is open.

I found the following code on Microsoft's Web site. It properly
determines if the Master workbook is open, but using it to test the
shared file produces a False result (i.e., file is not open) even if
the file is in use.

'-------------------
Function IsFileOpen(filename As String)
Dim filenum As Integer, errnum As Integer

On Error Resume Next ' Turn error checking off.
filenum = FreeFile() ' Get a free file number.
' Attempt to open the file and lock it.
Open filename For Input Lock Read As #filenum
Close filenum ' Close the file.
errnum = Err ' Save the error number that occurred.
On Error GoTo 0 ' Turn error checking back on.

' Check to see which error occurred.
Select Case errnum

' No error occurred.
' File is NOT already open by another user.
Case 0
IsFileOpen = False

' Error number for "Permission Denied."
' File is already opened by another user.
Case 70
IsFileOpen = True

' Another error occurred.
Case Else
Error errnum
End Select

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

Is there some other method I can use to find out if the shared
workbook is open? I would prefer not to have to actually open it via
code, but I'm willing to do so if there's no better alternative.

Mark Lincoln
 
Reply With Quote
 
 
 
 
Mark Lincoln
Guest
Posts: n/a
 
      13th Feb 2008
Based on some code from Microsoft, I've come up with a method that
works well enough:

'-------------------------------
Dim Users As Variant
Dim HowMany As Integer

Sub HowManyUsers()

Workbooks.Open ("F:\Foo\LookupFile.xls")

Users = ActiveWorkbook.UserStatus

HowMany = UBound(Users, 1)

MsgBox "Users: " & CStr(HowMany)

End Sub
'-------------------------------

If HowMany = 1, then only one person (i.e., the user running the Sub)
has the file open. If that's the case, I can then have my code close
the file and get on with the updating.

I still wish there was a way to do this without opening the file, but
even the Novell server never shows the Lookup file as being in use
except for a moment when it's first opened.

Mark Lincoln


On Feb 12, 4:43*pm, Mark Lincoln <mlinc...@earthlink.net> wrote:
> Is there a way to determine if a shared workbook on a (Novell NetWare)
> network drive is in use? *I need to be able to replace a locked-down
> shared workbook (for viewing by Those Who Should Not Make Changes)
> with an updated copy produced from a non-shared Master file. *I use a
> separate workbook (I have my reasons) to open the Master file, save it
> as an intermediate file, lock all its cells, protect all its sheets,
> and save the resulting file in place of the old shared workbook.
> Trying to save the file when someone has the old shared workbook open
> will actually work, but not without some problems. *So I don't want
> the update code to run if either file is open.
>
> I found the following code on Microsoft's Web site. *It properly
> determines if the Master workbook is open, but using it to test the
> shared file produces a False result (i.e., file is not open) even if
> the file is in use.
>
> '-------------------
> Function IsFileOpen(filename As String)
> * * Dim filenum As Integer, errnum As Integer
>
> * * On Error Resume Next * ' Turn error checking off.
> * * filenum = FreeFile() * ' Get a free file number.
> * * ' Attempt to open the file and lock it.
> * * Open filename For Input Lock Read As #filenum
> * * Close filenum * * * * *' Close the file.
> * * errnum = Err * * * * * ' Save the error number that occurred.
> * * On Error GoTo 0 * * * *' Turn error checking back on.
>
> * * ' Check to see which error occurred.
> * * Select Case errnum
>
> * * * * ' No error occurred.
> * * * * ' File is NOT already open by another user.
> * * * * Case 0
> * * * * *IsFileOpen = False
>
> * * * * ' Error number for "Permission Denied."
> * * * * ' File is already opened by another user.
> * * * * Case 70
> * * * * * * IsFileOpen = True
>
> * * * * ' Another error occurred.
> * * * * Case Else
> * * * * * * Error errnum
> * * End Select
>
> End Function
> '-------------------
>
> Is there some other method I can use to find out if the shared
> workbook is open? *I would prefer not to have to actually open it via
> code, but I'm willing to do so if there's no better alternative.
>
> Mark Lincoln


 
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
Determine if workbook is open Robert Crandal Microsoft Excel Programming 2 23rd Feb 2010 09:05 PM
Determine if a workbook is already open =?Utf-8?B?aHpndDliQG5vcG9zdC5jb20=?= Microsoft Excel Programming 6 28th Feb 2007 04:05 PM
Re: How can I determine who has workbook open? rjamison Microsoft Excel Programming 0 14th Jun 2005 12:14 AM
How can I determine who has workbook open? =?Utf-8?B?RGVhbiBIaW5zb24=?= Microsoft Excel Programming 3 20th Apr 2005 04:01 PM
Determine if a workbook is shared =?Utf-8?B?cXVhcnR6?= Microsoft Excel Programming 3 2nd Mar 2004 10:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:52 PM.