View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Roger Govier
 
Posts: n/a
Default Including Environ Username in Cell

Hi
Where are you pasting the code?
It needs to be in a general module of the workbook you are using, not in
the Sheet code.
--
Regards

Roger Govier


"Roger Govier" wrote in message
...
Hi

I found this function on Google, which I have used successfully.
I'm sorry but I don't have the author's name to give proper
accreditation, but whoever it is, thanks - I have found it useful.

=Getname(2) entered in a cell will return the user name


Function GetName(Optional NameType As String) As String
'Formula should be entered as =GetName([param])
'
'For Name of Type Enter Text OR Enter #
'MS Office User Name "Office" 1 (or leave blank)
'Windows User Name "Windows" 2
'Computer Name "Computer" 3

'Force application to recalculate when necessary. If this
'function is only called from other VBA procedures, this
'section can be eliminated. (Req'd for cell use)
Application.Volatile

'Set value to Office if no parameter entered
If Len(NameType) = 0 Then NameType = "OFFICE"

'Identify parameter, assign result to GetName, and return
'error if invalid
Select Case UCase(NameType)
Case Is = "OFFICE", "1"
GetName = Application.UserName
Exit Function
Case Is = "WINDOWS", "2"
GetName = Environ("UserName")
Exit Function
Case Is = "COMPUTER", "3"
GetName = Environ("ComputerName")
Exit Function
Case Else
GetName = CVErr(xlErrValue)
End Select

End Function

--
Regards

Roger Govier


"swieduwi"
wrote in message
...

I have searched the forum several way to resolve my issue and the
only
solutions were as follows:


Formula:
--------------------

Public Function UserName()
UserName = Environ("username")
'UserName = Computer("UserName")
End Function
MsgBox Environ("username")

Option Explicit
Function NetworkUserName() As String
Dim response
NetworkUserName = Environ("Username")
End Function

--------------------


Problem is that I get a #REF! and #NAME! instead of the user names
I am using Excel 2000 (I can not upgrade, Government PC) pus we need
it
to support Excel 2000 - present versions.

thanks


--
swieduwi
------------------------------------------------------------------------
swieduwi's Profile:
http://www.excelforum.com/member.php...o&userid=21962
View this thread:
http://www.excelforum.com/showthread...hreadid=507221