The first thing a coder should do is to check if the file exists. You can use Dir() to do that or one of various other methods. If it does, then check to see if it is open may be needed. Some users do not have access to some network drives and folders.
The GetFileOwner routine only works for 2003 so if a problem occurs, that routine might show who has the file open.
Sub Test_GetFileOwner() MsgBox GetFileOwner(ThisWorkbook.FullName)
End Sub
' http://www.ozgrid.com/forum/showthread.php?t=143957
Function GetFileOwner(fileName As String) As String
Dim secUtil As Object
Dim secDesc As Object
Dim File_Shortname As String
Dim fileDir As String
File_Shortname = Dir(fileName)
fileDir = Left(fileName, InStr(1, fileName, File_Shortname) - 1)
Set secUtil = CreateObject("ADsSecurityUtility")
Set secDesc = secUtil.GetSecurityDescriptor(fileDir & File_Shortname, 1, 1)
GetFileOwner = secDesc.owner
End Function
Sub Test_IsWorkbookOPen()
MsgBox IsWorkbookOpen("Personal.xls"), , "Personal.xls Open?"
MsgBox IsWorkbookOpen("Personal.xlsb"), , "Personal.xlsb Open?"
End Sub
Function IsWorkbookOpen(stName As String) As Boolean
Dim Wkb As Workbook
On Error Resume Next ' In Case it isn't Open
Set Wkb = Workbooks(stName)
If Not Wkb Is Nothing Then IsWorkbookOpen = True
'Boolean Function assumed To be False unless Set To True
End Function