Check if Excel File is Open
AND by Who
Thanks for visiting my site lucky visitor:
Copyright © 2002. XcelFiles. All Rights Reserved Ivan F Moala



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.
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.
by Helen Toomik and contributions from Mark Rowlinson , Insomniac & Mike_R .
This page was created on: 2 October, 2003
This page was last updated: 18 March, 2008