Add user name to cell

  • Thread starter Thread starter drswanker
  • Start date Start date
i dont know what do you mean... if you could only eleborate you
problem, maybe i can help you...
specify your point...
thnks...:confused
 
Ryan,

Example: If A1 = (today's date) than I would like A2 = the window
user name. Not sure if this is possible. I just need to know how t
get the user name. I know how to auto populate based on another feild.
I thought since excel has the user info stored it would be possible t
populate a cell with that info. (when multiple people open a doc. th
second person to open has the option to notify the user currently wit
write access
 
One way would be to create your own function, in the workbook you want this
press Alt + F11, click Insert>Module and paste in this (Don't remember whom
I copied it from)

public function CurrentUser() as string
CurrentUser=Application.UserName
end function

press Alt + Q to close the VBE, save the workbook

Now in A2 use this formula

=IF(A1=TODAY(),currentuser(),"")
 
Peo's UDF will return the username entered in Excel's Tools>Options>General
which is not necessarily the Windows Username if that's what you want.

Bob Phillips donated the following to go a level deeper to get the Windows
logged on Username.

Public Declare Function GetUserName Lib "advapi32.dll" _
Alias "GetUserNameA" _
(ByVal lpBuffer As String, _
nSize As Long) As Long

Public Function UserName() As String
Dim sName As String * 256
Dim cChars As Long
cChars = 256
If GetUserName(sName, cChars) Then
UserName = Left$(sName, cChars - 1)
End If
End Function

Usage is: =username()

Gord Dibben XL2002
 
drswanker,
i guess im late...Peo Sjoblom is right...the only thing you can do i
to create your own function...
the tip that Peo Sjoblom gave you is right...go to excel vba code...
you can also try to right click your mouse on the sheet, then selec
view code...
put that script to a module..
if you want that in every time you open that workbook, you can ad
this

go to view, then select the project explorer, then your projec
explorer will pop-up, then select "Sheet1"
at the top-left most part you can see "(General)", change it t
"Workbook", then on the top-right you see "(Open)" change it t
"Activate"

then
type this one

Range("a1").value=CurrentUser()
Range("a2").value=Now()

so, every time you activate that sheet, A1 is always the username, an
a2 is always the Date.

you can also explore the VBA of excel...try it and you'll going to lik
it...

thnks...









:
 
Back
Top