This is a good one:
How do you use VB to capture a "username" that can be used in an excell worksheet via a messagebox or when opening a spreadsheet?
Any one???!!!Ferris...Any body!!??
Thanx
If ur on NT, then
Environ("Username" will return the user logon name
else
Application.username will return the excel username (only if set up right)
Other than that, it's an API call -
Public UserName As String
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Sub Get_User_Name()
Dim lpBuff As String * 25
Dim ret As Long
ret = GetUserName(lpBuff, 25)
UserName = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
End Sub
Hey Geoff - it did not work for me.
where i would write this function? the goal is to populate a msgbox that tells me who was the last person to have modified that workbook! THe function below did not work for me either:
Sub ShowFileAccessInfo(filespec)
Dim fs, f, s
Set fs = CreateObject("Scripting.FileSystemObject"
Set f = fs.GetFile(filespec)
s = UCase(filespec) & vbCrLf
s = s & "Created: " & f.DateCreated & vbCrLf
s = s & "Last Accessed: " & f.DateLastAccessed & vbCrLf
s = s & "Last Modified: " & f.DateLastModified
MsgBox s, 0, "File Access Info"
Put the code in the Before save Event - that way it'll only capture the name when a change has ben made and saved.
The functions will return a text string that is the username - you'll need to populate a cell on the worksheet to retain that username for when you open the spreadsheet. So, if you are on NT,
In the before save event
mUser = environ("Username"
with sheets("logsheet"
.range("A1".value = mUser
End with
Then on workbook open event
msgbox sheets("Logsheet".range("A1".text
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.