Hi,
I'm trying to adapt some code to check if a file is already open (get the name of the 'owner' and pass it back) and give the user the option to try again. I plan to create a small userform with a label caption and a button to try again - "... goto tryagain"
However, I'm failing at the first hurdle as I get a runtime error 450 on GetSecurityDescriptor in the function.
I've probably done something stupid, but can't see it - maybe because it's a Friday afternoon and I'm a bit tired...
Code in sub:
If Dir(PymtTLPath, vbDirectory) = "" Then
TempPTPath = Range("nrTempPTPath") 'contains filepath, allows user to ammend if need be
Workbooks.Open fileName:=TempPTPath, Password:="xxx"
If ActiveWorkbook.ReadOnly Then
MsgBox "The file is locked by " & GetFileOwner(TempPTPath) & "."
'code to be amended here to close the file, change message box to lable caption in a userform and give the user the option to try again
End If
Else
Workbooks.Open fileName:=PymtTLPath, Password:="xxx" 'if the file already exists, open it
End If
Code in function:
Function GetFileOwner(FilePath As String) As String
Dim secUtil As Object
Dim secDesc As Object
Set secUtil = CreateObject("ADsSecurityUtility")
Set secDesc = secUtil.GetSecurityDescriptor(FilePath)
GetFileOwner = secDesc.owner
End Function
Anyone spot the obvious mistake?!
Thanks, TC
Bookmarks