Check if Excel File is Open
AND by Who
Can Do
Goto Guest book sign in page [Home]
Thanks for visiting my site lucky visitor:
Copyright © 2002. XcelFiles. All Rights Reserved Ivan F Moala
Tell a friend about this page
Ever needed to know if a Workbook was already open ? Yes ? then you may have used something along these lines......

Function CheckFile(strFile As String) As Boolean
Dim Wbk As Workbook

   CheckFile = False
   On Error GoTo NotOpen
   Set Wbk = workbooks(strFile)
   CheckFile = True

   Exit Function
NotOpen:

End Function

Nothing wrong with these types of Functions.....BUT what if the file to check is on a Network Drive, in which case it is accessible for everyone to open it.
The above Function really only checks to see if you have it Open.

So it really isn't any good for checking what files are already open, except by you, ie. someone else may have it open.

Here are a couple of ways to test if a file is already Open, AND it gets the User Name of who has the File Open, similar to what you get if you try and open an Excel file and you get this;










Note: User Name as inputted into the Applications User Name option. So if you are like Yevette, who asked at MrExcel that one of here users does not have a name inputed here then you are out of luck.

If I find a way to get the logged on user name I will up date this here.

1st method uses API's
2nd method uses VBA.

The VBA version just simulates what is really happening in the API version.
I put these here so that you can see that many VBA methods are really just a top layer to the underlying API calls.

The UserName code was amended from code from this excellent thread
by Helen Toomik and contributions from Mark Rowlinson , Insomniac & Mike_R .



                  Download Example WorkBook

API Method
VBA Method
Google
Search WWW Search My Site!

This page was created on: 2 October, 2003
This page was last updated: 18 March, 2008
Excel is a useful tool, and is even more beneficial if you have a PDF to Excel converter. You can use just about any PDF converter to make a PDF, but converting a PDF to Excel, Word or Doc is something you'll use for years to come.