I'm looking for some code to tell me the username of the user that has an Excel (.xls) file open. Currently, the code will throw up a msgbox if the file opens as read only, but I also want it to tell me who has it open. It gives the name when opening manually as a "locked for editing" error message. Is this a possible function to add?
I've researched many websites but have not found one suitable, or just had no answers at all.
I have also looked into reading the locked file that gets created, but still cannot get it to work.
xlApp = New Microsoft.Office.Interop.Excel.ApplicationClass
xlWorkBook = xlApp.Workbooks.Open("\\********", IO.FileAccess.Write)
If xlWorkBook.ReadOnly = True Then
xlWorkBook.Close(SaveChanges:=False)
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
MsgBox("Workbook Open")
Else
xlApp.Visible = True
End If
Where the msgbox is, I would like it to show the username of who has it open.