I have searched the forum several way to resolve my issue and the only
solutions were as follows:PHP code:
--------------------
Public Function UserName()
UserName = Environ(quot;usernamequot;)
'UserName = Computer(quot;UserNamequot;)
End Function
MsgBox Environ(”username”)
Option Explicit
Function NetworkUserName() As String
Dim response
NetworkUserName = Environ(quot;Usernamequot;)
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: www.excelforum.com/member.php...oamp;userid=21962
View this thread: www.excelforum.com/showthread...hreadid=507221
Bump
Any Takers--
swieduwi
------------------------------------------------------------------------
swieduwi's Profile: www.excelforum.com/member.php...oamp;userid=21962
View this thread: www.excelforum.com/showthread...hreadid=507221Hi
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 nameFunction 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 quot;Officequot; 1 (or leave blank)
'Windows User Name quot;Windowsquot; 2
'Computer Name quot;Computerquot; 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 = quot;OFFICEquot;
'Identify parameter, assign result to GetName, and return
'error if invalid
Select Case UCase(NameType)
Case Is = quot;OFFICEquot;, quot;1quot;
GetName = Application.UserName
Exit Function
Case Is = quot;WINDOWSquot;, quot;2quot;
GetName = Environ(quot;UserNamequot;)
Exit Function
Case Is = quot;COMPUTERquot;, quot;3quot;
GetName = Environ(quot;ComputerNamequot;)
Exit Function
Case Else
GetName = CVErr(xlErrValue)
End Select
End Function
--
Regards
Roger Govierquot;swieduwiquot; gt; wrote
in message ...
gt;
gt; I have searched the forum several way to resolve my issue and the only
gt; solutions were as follows:
gt;
gt;
gt; PHP code:
gt; --------------------
gt;
gt; Public Function UserName()
gt; UserName = Environ(quot;usernamequot;)
gt; 'UserName = Computer(quot;UserNamequot;)
gt; End Function
gt; MsgBox Environ(quot;usernamequot;)
gt;
gt; Option Explicit
gt; Function NetworkUserName() As String
gt; Dim response
gt; NetworkUserName = Environ(quot;Usernamequot;)
gt; End Function
gt;
gt; --------------------
gt;
gt;
gt; Problem is that I get a #REF! and #NAME! instead of the user names
gt; I am using Excel 2000 (I can not upgrade, Government PC) pus we need
gt; it
gt; to support Excel 2000 - present versions.
gt;
gt; thanks
gt;
gt;
gt; --
gt; swieduwi
gt; ------------------------------------------------------------------------
gt; swieduwi's Profile:
gt; www.excelforum.com/member.php...oamp;userid=21962
gt; View this thread:
gt; www.excelforum.com/showthread...hreadid=507221
gt;
the =Getname(2) did not work as well, I get the #NAME?
What am I doing wrong??????--
swieduwi
------------------------------------------------------------------------
swieduwi's Profile: www.excelforum.com/member.php...oamp;userid=21962
View this thread: www.excelforum.com/showthread...hreadid=507221Hi
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 Govierquot;Roger Govierquot; gt; wrote in message
...
gt; Hi
gt;
gt; I found this function on Google, which I have used successfully.
gt; I'm sorry but I don't have the author's name to give proper
gt; accreditation, but whoever it is, thanks - I have found it useful.
gt;
gt; =Getname(2) entered in a cell will return the user name
gt;
gt;
gt; Function GetName(Optional NameType As String) As String
gt; 'Formula should be entered as =GetName([param])
gt; '
gt; 'For Name of Type Enter Text OR Enter #
gt; 'MS Office User Name quot;Officequot; 1 (or leave blank)
gt; 'Windows User Name quot;Windowsquot; 2
gt; 'Computer Name quot;Computerquot; 3
gt;
gt; 'Force application to recalculate when necessary. If this
gt; 'function is only called from other VBA procedures, this
gt; 'section can be eliminated. (Req'd for cell use)
gt; Application.Volatile
gt;
gt; 'Set value to Office if no parameter entered
gt; If Len(NameType) = 0 Then NameType = quot;OFFICEquot;
gt;
gt; 'Identify parameter, assign result to GetName, and return
gt; 'error if invalid
gt; Select Case UCase(NameType)
gt; Case Is = quot;OFFICEquot;, quot;1quot;
gt; GetName = Application.UserName
gt; Exit Function
gt; Case Is = quot;WINDOWSquot;, quot;2quot;
gt; GetName = Environ(quot;UserNamequot;)
gt; Exit Function
gt; Case Is = quot;COMPUTERquot;, quot;3quot;
gt; GetName = Environ(quot;ComputerNamequot;)
gt; Exit Function
gt; Case Else
gt; GetName = CVErr(xlErrValue)
gt; End Select
gt;
gt; End Function
gt;
gt; --
gt; Regards
gt;
gt; Roger Govier
gt;
gt;
gt; quot;swieduwiquot; gt;
gt; wrote in message
gt; ...
gt;gt;
gt;gt; I have searched the forum several way to resolve my issue and the
gt;gt; only
gt;gt; solutions were as follows:
gt;gt;
gt;gt;
gt;gt; PHP code:
gt;gt; --------------------
gt;gt;
gt;gt; Public Function UserName()
gt;gt; UserName = Environ(quot;usernamequot;)
gt;gt; 'UserName = Computer(quot;UserNamequot;)
gt;gt; End Function
gt;gt; MsgBox Environ(quot;usernamequot;)
gt;gt;
gt;gt; Option Explicit
gt;gt; Function NetworkUserName() As String
gt;gt; Dim response
gt;gt; NetworkUserName = Environ(quot;Usernamequot;)
gt;gt; End Function
gt;gt;
gt;gt; --------------------
gt;gt;
gt;gt;
gt;gt; Problem is that I get a #REF! and #NAME! instead of the user names
gt;gt; I am using Excel 2000 (I can not upgrade, Government PC) pus we need
gt;gt; it
gt;gt; to support Excel 2000 - present versions.
gt;gt;
gt;gt; thanks
gt;gt;
gt;gt;
gt;gt; --
gt;gt; swieduwi
gt;gt; ------------------------------------------------------------------------
gt;gt; swieduwi's Profile:
gt;gt; www.excelforum.com/member.php...oamp;userid=21962
gt;gt; View this thread:
gt;gt; www.excelforum.com/showthread...hreadid=507221
gt;gt;
gt;
gt;
Roger Govier Wrote:
gt; Hi
gt; Where are you pasting the code?
gt; It needs to be in a general module of the workbook you are using, not
gt; in
gt; the Sheet code.
gt; --
gt; Regards
gt;
gt; Roger Govier
gt;
gt; gt;[/color]
Thanks for the reply...
Yes I placed it in the General section of my Workbook code area and it
looks like this:
PHP code:
--------------------
Public Function UserName()
Select Case UCase(NameType)
Case Is = quot;OFFICEquot;, quot;1quot;
GetName = Application.UserName
Exit Function
Case Is = quot;WINDOWSquot;, quot;2quot;
GetName = Environ(quot;UserNamequot;)
Exit Function
Case Is = quot;COMPUTERquot;, quot;3quot;
GetName = Environ(quot;ComputerNamequot;)
Exit Function
Case Else
GetName = CVErr(xlErrValue)
End Select
End Function
--------------------
in the cell I reference quot;=username()quot; I get a #REF! in the Cell
if I reference quot;=GetName(2) i get a #NAME?--
swieduwi
------------------------------------------------------------------------
swieduwi's Profile: www.excelforum.com/member.php...oamp;userid=21962
View this thread: www.excelforum.com/showthread...hreadid=507221The code needs to be in a regular code module, NOT the
ThisWorkbook module or a sheet module.--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.comquot;swieduwiquot;
gt; wrote in
message
...
gt;
gt; Roger Govier Wrote:
gt;gt; Hi
gt;gt; Where are you pasting the code?
gt;gt; It needs to be in a general module of the workbook you are
gt;gt; using, not
gt;gt; in
gt;gt; the Sheet code.
gt;gt; --
gt;gt; Regards
gt;gt;
gt;gt; Roger Govier
gt;gt;
gt;gt; gt;
gt; Thanks for the reply...
gt;
gt; Yes I placed it in the General section of my Workbook code area
gt; and it
gt; looks like this:
gt;
gt; PHP code:
gt; --------------------
gt;
gt; Public Function UserName()
gt;
gt; Select Case UCase(NameType)
gt; Case Is = quot;OFFICEquot;, quot;1quot;
gt; GetName = Application.UserName
gt; Exit Function
gt; Case Is = quot;WINDOWSquot;, quot;2quot;
gt; GetName = Environ(quot;UserNamequot;)
gt; Exit Function
gt; Case Is = quot;COMPUTERquot;, quot;3quot;
gt; GetName = Environ(quot;ComputerNamequot;)
gt; Exit Function
gt; Case Else
gt; GetName = CVErr(xlErrValue)
gt; End Select
gt;
gt; End Function
gt;
gt; --------------------
gt;
gt; in the cell I reference quot;=username()quot; I get a #REF! in the Cell
gt; if I reference quot;=GetName(2) i get a #NAME?
gt;
gt;
gt; --
gt; swieduwi
gt; ------------------------------------------------------------------------
gt; swieduwi's Profile:
gt; www.excelforum.com/member.php...oamp;userid=21962
gt; View this thread:
gt; www.excelforum.com/showthread...hreadid=507221
gt;[/color]
quot;Roger Govierquot; gt; wrote in message
gt; Function GetName(Optional NameType As String) As String
This function should have a return type of Variant, not String,
since one possible return value is CVErr(xlErrValue). Also, the
NameType should be declared ByVal -- it is bad form to change
argument values in the calling procedure unless it is required by
design.--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.comquot;Roger Govierquot; gt; wrote in message
...
gt; Hi
gt;
gt; I found this function on Google, which I have used
gt; successfully.
gt; I'm sorry but I don't have the author's name to give proper
gt; accreditation, but whoever it is, thanks - I have found it
gt; useful.
gt;
gt; =Getname(2) entered in a cell will return the user name
gt;
gt;
gt; Function GetName(Optional NameType As String) As String
gt; 'Formula should be entered as =GetName([param])
gt; '
gt; 'For Name of Type Enter Text OR Enter #
gt; 'MS Office User Name quot;Officequot; 1 (or leave
gt; blank)
gt; 'Windows User Name quot;Windowsquot; 2
gt; 'Computer Name quot;Computerquot; 3
gt;
gt; 'Force application to recalculate when necessary. If this
gt; 'function is only called from other VBA procedures, this
gt; 'section can be eliminated. (Req'd for cell use)
gt; Application.Volatile
gt;
gt; 'Set value to Office if no parameter entered
gt; If Len(NameType) = 0 Then NameType = quot;OFFICEquot;
gt;
gt; 'Identify parameter, assign result to GetName, and return
gt; 'error if invalid
gt; Select Case UCase(NameType)
gt; Case Is = quot;OFFICEquot;, quot;1quot;
gt; GetName = Application.UserName
gt; Exit Function
gt; Case Is = quot;WINDOWSquot;, quot;2quot;
gt; GetName = Environ(quot;UserNamequot;)
gt; Exit Function
gt; Case Is = quot;COMPUTERquot;, quot;3quot;
gt; GetName = Environ(quot;ComputerNamequot;)
gt; Exit Function
gt; Case Else
gt; GetName = CVErr(xlErrValue)
gt; End Select
gt;
gt; End Function
gt;
gt; --
gt; Regards
gt;
gt; Roger Govier
gt;
gt;
gt; quot;swieduwiquot;
gt; gt; wrote
gt; in message
gt; ...
gt;gt;
gt;gt; I have searched the forum several way to resolve my issue and
gt;gt; the only
gt;gt; solutions were as follows:
gt;gt;
gt;gt;
gt;gt; PHP code:
gt;gt; --------------------
gt;gt;
gt;gt; Public Function UserName()
gt;gt; UserName = Environ(quot;usernamequot;)
gt;gt; 'UserName = Computer(quot;UserNamequot;)
gt;gt; End Function
gt;gt; MsgBox Environ(quot;usernamequot;)
gt;gt;
gt;gt; Option Explicit
gt;gt; Function NetworkUserName() As String
gt;gt; Dim response
gt;gt; NetworkUserName = Environ(quot;Usernamequot;)
gt;gt; End Function
gt;gt;
gt;gt; --------------------
gt;gt;
gt;gt;
gt;gt; Problem is that I get a #REF! and #NAME! instead of the user
gt;gt; names
gt;gt; I am using Excel 2000 (I can not upgrade, Government PC) pus
gt;gt; we need it
gt;gt; to support Excel 2000 - present versions.
gt;gt;
gt;gt; thanks
gt;gt;
gt;gt;
gt;gt; --
gt;gt; swieduwi
gt;gt; ------------------------------------------------------------------------
gt;gt; swieduwi's Profile:
gt;gt; www.excelforum.com/member.php...oamp;userid=21962
gt;gt; View this thread:
gt;gt; www.excelforum.com/showthread...hreadid=507221
gt;gt;
gt;
gt;
Hi Chip
Many thanks for pointing this out. My VBA skills are limited, but
growing through participation here.
As I said in my first response to the OP, I found the routine somewhere
through a search on the web, and don't know the author.
Thus far, it has worked OK for me, but I guess I've been lucky and not
hit the Err values you mention.
I will change the routine accordingly.
If I understand you correctly, this should be
Function GetName(Optional NameType ByVal) As Variant.
Is this correct?
--
Regards
Roger Govierquot;Chip Pearsonquot; gt; wrote in message
...
gt; quot;Roger Govierquot; gt; wrote in message
gt;
gt;gt; Function GetName(Optional NameType As String) As String
gt;
gt; This function should have a return type of Variant, not String, since
gt; one possible return value is CVErr(xlErrValue). Also, the NameType
gt; should be declared ByVal -- it is bad form to change argument values
gt; in the calling procedure unless it is required by design.
gt;
gt;
gt; --
gt; Cordially,
gt; Chip Pearson
gt; Microsoft MVP - Excel
gt; Pearson Software Consulting, LLC
gt; www.cpearson.com
gt;
gt;
gt;
gt;
gt;
gt; quot;Roger Govierquot; gt; wrote in message
gt; ...
gt;gt; Hi
gt;gt;
gt;gt; I found this function on Google, which I have used successfully.
gt;gt; I'm sorry but I don't have the author's name to give proper
gt;gt; accreditation, but whoever it is, thanks - I have found it useful.
gt;gt;
gt;gt; =Getname(2) entered in a cell will return the user name
gt;gt;
gt;gt;
gt;gt; Function GetName(Optional NameType As String) As String
gt;gt; 'Formula should be entered as =GetName([param])
gt;gt; '
gt;gt; 'For Name of Type Enter Text OR Enter #
gt;gt; 'MS Office User Name quot;Officequot; 1 (or leave blank)
gt;gt; 'Windows User Name quot;Windowsquot; 2
gt;gt; 'Computer Name quot;Computerquot; 3
gt;gt;
gt;gt; 'Force application to recalculate when necessary. If this
gt;gt; 'function is only called from other VBA procedures, this
gt;gt; 'section can be eliminated. (Req'd for cell use)
gt;gt; Application.Volatile
gt;gt;
gt;gt; 'Set value to Office if no parameter entered
gt;gt; If Len(NameType) = 0 Then NameType = quot;OFFICEquot;
gt;gt;
gt;gt; 'Identify parameter, assign result to GetName, and return
gt;gt; 'error if invalid
gt;gt; Select Case UCase(NameType)
gt;gt; Case Is = quot;OFFICEquot;, quot;1quot;
gt;gt; GetName = Application.UserName
gt;gt; Exit Function
gt;gt; Case Is = quot;WINDOWSquot;, quot;2quot;
gt;gt; GetName = Environ(quot;UserNamequot;)
gt;gt; Exit Function
gt;gt; Case Is = quot;COMPUTERquot;, quot;3quot;
gt;gt; GetName = Environ(quot;ComputerNamequot;)
gt;gt; Exit Function
gt;gt; Case Else
gt;gt; GetName = CVErr(xlErrValue)
gt;gt; End Select
gt;gt;
gt;gt; End Function
gt;gt;
gt;gt; --
gt;gt; Regards
gt;gt;
gt;gt; Roger Govier
gt;gt;
gt;gt;
gt;gt; quot;swieduwiquot; gt;
gt;gt; wrote in message
gt;gt; ...
gt;gt;gt;
gt;gt;gt; I have searched the forum several way to resolve my issue and the
gt;gt;gt; only
gt;gt;gt; solutions were as follows:
gt;gt;gt;
gt;gt;gt;
gt;gt;gt; PHP code:
gt;gt;gt; --------------------
gt;gt;gt;
gt;gt;gt; Public Function UserName()
gt;gt;gt; UserName = Environ(quot;usernamequot;)
gt;gt;gt; 'UserName = Computer(quot;UserNamequot;)
gt;gt;gt; End Function
gt;gt;gt; MsgBox Environ(quot;usernamequot;)
gt;gt;gt;
gt;gt;gt; Option Explicit
gt;gt;gt; Function NetworkUserName() As String
gt;gt;gt; Dim response
gt;gt;gt; NetworkUserName = Environ(quot;Usernamequot;)
gt;gt;gt; End Function
gt;gt;gt;
gt;gt;gt; --------------------
gt;gt;gt;
gt;gt;gt;
gt;gt;gt; Problem is that I get a #REF! and #NAME! instead of the user names
gt;gt;gt; I am using Excel 2000 (I can not upgrade, Government PC) pus we need
gt;gt;gt; it
gt;gt;gt; to support Excel 2000 - present versions.
gt;gt;gt;
gt;gt;gt; thanks
gt;gt;gt;
gt;gt;gt;
gt;gt;gt; --
gt;gt;gt; swieduwi
gt;gt;gt; ------------------------------------------------------------------------
gt;gt;gt; swieduwi's Profile:
gt;gt;gt; www.excelforum.com/member.php...oamp;userid=21962
gt;gt;gt; View this thread:
gt;gt;gt; www.excelforum.com/showthread...hreadid=507221
gt;gt;gt;
gt;gt;
gt;gt;
gt;
gt;
This works fine but I am trying to show the last person who saved the
file,
I need to track who changed the file last since is resides on a network
drive.
this shows who currently has the sheet open.--
swieduwi
------------------------------------------------------------------------
swieduwi's Profile: www.excelforum.com/member.php...oamp;userid=21962
View this thread: www.excelforum.com/showthread...hreadid=507221
- Jul 25 Fri 2008 20:44
Including Environ Username in Cell
close
全站熱搜
留言列表
發表留言