I have been trying to get this to work for last few days and cant seem to understand why. I was able to get it to work via mapped drive but I don't want to use that method. I want to use the unc path instead. It seems to work for the sub section but gets to function side and says invalid object found.
Rich (BB code):
Sub Used()
'testWorkbookLockFile = "K:\~$FileName.xlsm"
mypath = "\\IP\Folder\~$FileName.xlsm"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(mypath) Then
Set TxtRng = ActiveWorkbook.Sheets("Sheet1").Cells(1, 1)
TxtRng.Value = "The file is locked by " & GetFileOwner(mypath)
Else
Set TxtRng = ActiveWorkbook.Sheets("Sheet1").Cells(1, 1)
TxtRng.Value = "The file is available"
End If
End Sub
Function GetFileOwner(strFilename)
Set objWMIService = GetObject("winmgmts:")
Set objFileSecuritySettings = _ <<<
objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFilename & "'") <<<< says not found and only when someone has it open but the strfilename gets passed as it should
intRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD)
If intRetVal = 0 Then
GetFileOwner = objSD.owner.Name
Else
GetFileOwner = "Unknown"
End If
End Function
Last edited by a moderator: