Please refer below vb.net code, you can invoke it in Uipath.
Private Sub Workbook_Open()
Dim Folder As String
Dim FName As String
Dim strFilename As String
Folder = “C:”
FName = “data.xls”
If Not FileLocked(Folder & FName) Then
MsgBox “File " & Folder & FName & " is not open”
MsgBox "The file is locked by " & GetFileOwner(Folder, FName) & “.”
Function GetFileOwner(fileDir As String, fileName As String) As String
'On Error Resume Next
Dim secUtil As Object
Dim secDesc As Object
Set secUtil = CreateObject(“ADsSecurityUtility”)
Set secDesc = secUtil.GetSecurityDescriptor(fileDir & fileName, 1, 1)
GetFileOwner = secDesc.Owner
Function FileLocked(strFilename As String) As Boolean
On Error Resume Next
’ If the file is already opened by another process,
’ and the specified type of access is not allowed,
’ the Open operation fails and an error occurs.
Open strFilename For Binary Access Read Write Lock Read Write As #1
’ If an error occurs, the document is currently open.
If Err.Number <> 0 Then
’ Display the error number and description.
'MsgBox “Error #” & Str(Err.Number) & " - " & Err.Description
FileLocked = True