Hi,
I have the following code that was created by someone else to capture users' log ins in an Excel spreadsheet. I cannot get the code to work.
Range("A1") = CName()
Public Function CName() As String
'This function will get the login user ID of the person logged into the computer
Dim strUserName As String
Dim NBuffer As String
Dim Buffsize As Long
Dim Wok As Long
Buffsize = 256
NBuffer = Space$(Buffsize)
Wok = CurrentUserName(NBuffer, Buffsize)
strUserName = Trim$(NBuffer)
strUserName = Left$(strUserName, Len(strUserName) - 1)
CName = strUserName
End Function
At first, I got the err msg "Invalid outside procedure" and the debugger stopped at Range("A1") = CName() and highlighted CName(). So I moved this statement inside the function like so:
Public Function CName() As String
Range("A1") = CName()
'This function will get the login user ID of the person logged into the computer
Dim strUserName As String
Dim NBuffer As String
Dim Buffsize As Long
Dim Wok As Long
Buffsize = 256
NBuffer = Space$(Buffsize)
Wok = CurrentUserName(NBuffer, Buffsize)
strUserName = Trim$(NBuffer)
strUserName = Left$(strUserName, Len(strUserName) - 1)
CName = strUserName
End Function
Now the debugger stops at Wok = CurrentUserName(NBuffer, Buffsize) and highlights CurrentUserName. The err msg is Compile Error: Sub or Function Not Defined.
How can I get this macro to work?
Also, how can I get the users' logins to append in the column and not get overwritten each time someone opens the file? I'd like to see a daily history of the users who have been going into the spreadsheet.
Start Free Trial