0
Objectively:
How is it possible to know, with VBA, which name of the user has an excel file opened, that file is somewhere on a server and not on the local disk?
Context
I have searched for a function, in VBA, which let me know if an excel file is opened by a user and, if so, which is the name of the user.
I was able to find a routine that does this, but only if the open file is on the local disk, which is not my case, follows the function cited:
Function Excel_File_in_use_by(FilePath As String) As String
Dim strTempFile As String
Dim iPos As Integer, iRetVal As Integer
Dim objFSO As Object, objWMIService As Object, objFileSecuritySettings As Object, objSD As Object
iPos = InStrRev(FilePath, "\")
strTempFile = left(FilePath, iPos - 1) & "\~$" & Mid(FilePath, iPos + 1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strTempFile) Then
Set objWMIService = GetObject("winmgmts:")
Set objFileSecuritySettings = objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strTempFile & "'")
iRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD)
If iRetVal = 0 Then
Excel_File_in_use_by = objSD.Owner.Name
Else
Excel_File_in_use_by = "unknown"
End If
Set objWMIService = Nothing
Set objFileSecuritySettings = Nothing
Set objSD = Nothing
Else
Excel_File_in_use_by = vbNullString
End If
Set objFSO = Nothing
End Function
I needed a function to check if a specific file, in this case an excel365 file, placed on a specific server, is open by a user and, if so, what is the user’s name.
It is possible to do this in VBA?
How to implement this?
What is intended is not the Windows computer username, but the name of the user who has a particular file opened on a given server.
– JCabral
Your Office package is 2016? It does not work very well in VBA of this version and also depends on the version of Windows Server... But there are many examples of doing this in unsafe ways, many open vulnerabilities and depend on the way your server is configured and the version...
– danieltakeshi
I use Office365 with Windows10. I couldn’t find an example that indicates which user name has the file open, I can only find examples that tell me if the file is open or not.
– JCabral