Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Capture USERNAME - VB/Excell!!

Status
Not open for further replies.

HeyFrantz

Technical User
Jul 18, 2002
15
US
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

Any of these do ya ?? Rgds
~Geoff~
 
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"

End Sub
Thanks
 
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


HTH Rgds
~Geoff~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top