【发布时间】:2022-06-10 20:23:55
【问题描述】:
我想在 excel 文件中显示最后一个编辑者的名字。
是否可以通过Excel VBA获取最后编辑excel的编辑姓名?
【问题讨论】:
我想在 excel 文件中显示最后一个编辑者的名字。
是否可以通过Excel VBA获取最后编辑excel的编辑姓名?
【问题讨论】:
您可以为事件 Workbook_Open 创建一个宏,将当前用户名写入某个日志文件。在https://support.microsoft.com 他们有一个子来获取当前用户名
' Makes sure all variables are dimensioned in each subroutine.
Option Explicit
' Access the GetUserNameA function in advapi32.dll and ' call the function GetUserName.
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
' Main routine to Dimension variables, retrieve user name
' and display answer.
Sub Get_User_Name()
' Dimension variables
Dim lpBuff As String * 25
Dim ret As Long, UserName As String
' Get the user name minus any trailing spaces found in the name.
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
' Display the User Name
MsgBox UserName
End Sub
【讨论】:
您可能会受益于内置属性“last author”,每次保存都会刷新该属性,并且可以通过以下函数读取:
Private Function LastAuthor() As String
Dim prop As Object
On Error Resume Next
Set prop = ThisWorkbook.BuiltinDocumentProperties("last author")
If Err.Number = 0 Then
LastAuthor = prop.Value
Else
LastAuthor = "Not yet documented!"
End If
End Function
另一个感兴趣的内置属性可能是"Last save time"。
【讨论】: