如果打开的工作簿(位于服务器上)处于只读模式,如何使用VBA显示活动用户名?
我查看了.WriteReservedBy
,但这只显示了上次使用密码保存文件的人的姓名。
答案 0 :(得分:1)
这应该是评论,但我的声誉太低
我已经看过这个但从未需要这些信息...
要尝试的事情:
Declare Function WNetGetUser Lib "mpr.dll" Alias "WNetGetUserA"
( _
ByVal lpName As String, _
ByVal lpUserName As String, _
lpnLength As Long
) As Long
Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" _
(ByVal lpBuffer As String, nSize As Long)
有关这些API的更多详细信息:
Public Function GetActiveUser(Optional ByVal computer As String = ".") As String
Dim wmi As Object, itm As String
On Error Resume Next
Set wmi = GetObject("winmgmts:\\" & computer & "\Root\CIMv2")
itm = wmi.ExecQuery("Select UserName from Win32_NetworkConnection", , 48)
GetNetActiveUser = itm
End Function