View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Andrew[_56_] Andrew[_56_] is offline
external usenet poster
 
Posts: 130
Default Check for file open/closed status

On Nov 25, 6:53*pm, Vacuum Sealed wrote:
Hi all

I need help with the following please.

Check if myFile is open/closed, if it is open flash up a MsgBox
displaying ( if possible ) the user's identification.

There are some users in the office that have memory-holes between their
ears and leave files open after they have accessed and finished with
them. This specific file is backed up to at the end of each day and
upsets the whole process ( if left open ), when others forget to close it..

Something like:

If Workbook.myFile is open then

Msg("This person has the file open", vbOkOnly)
Cancel = True

Else

' Do my other stuff

I would like to have this run the check first so the user can cancel the
rest of the code if it is in use by someone else. He/She then can ask
the current user to close the file and continue.

Thx heaps in advance
Mick


Try this. It isn't as fancy, but it works.

On error resume next
dim WB as workbook
dim wbname as string

Set WB = Workbooks(wbname) 'Let wbname be the name of the open or
closed workbook

' If the workbook is not opened, the assignment in the previous line
' will result in an error. The error will tell you that the subscript
is out
' of range, the subscript being wbname. If there is an error, the
excel variable
' Err will ' be equal to a non zero value.

If Err < 0 Then
Reply = MsgBox("The Workbook " & wbname & " is not Open.")
End If