Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
User = Application.UserName
'Save the user and probably date time in wherever you want
End Sub
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
' 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
3条答案
按热度按时间1u4esq0p1#
我认为最简单的方法是使用这个内置函数。
您需要在“ThisWorkbook”模块中插入代码:
ycl3bljg2#
您可能会受益于内置属性“last author”,该属性在每次保存时都会刷新,并可由以下函数读取:
另一个感兴趣的内置属性可能是
"Last save time"
。lokaqttq3#
您可以为事件Workbook_Open创建宏,该宏在某些日志文件中写入当前用户名。在https://support.microsoft.com上,它们具有用于获取当前用户名的sub