Closed Thread
Results 1 to 10 of 10

Including Environ Username in Cell

  1. #1
    Registered User
    Join Date
    04-08-2005
    Location
    Washington, DC
    Posts
    63

    Including Environ Username in Cell

    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("username")
    'UserName = Computer("UserName")
    End Function


    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) plus we need it to support Excel 2000 - present versions.

    thanks

  2. #2
    Registered User
    Join Date
    04-08-2005
    Location
    Washington, DC
    Posts
    63
    Bump
    Any Takers ?
    Last edited by swieduwi; 02-01-2006 at 04:10 PM.

  3. #3
    Roger Govier
    Guest

    Re: Including Environ Username in Cell

    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" <[email protected]> wrote
    in message news:[email protected]...
    >
    > 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("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
    >




  4. #4
    Registered User
    Join Date
    04-08-2005
    Location
    Washington, DC
    Posts
    63
    the =Getname(2) did not work as well, I get the #NAME?
    What am I doing wrong??????

  5. #5
    Roger Govier
    Guest

    Re: 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" <[email protected]> wrote in message
    news:%[email protected]...
    > 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" <[email protected]>
    > wrote in message
    > news:[email protected]...
    >>
    >> 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("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
    >>

    >
    >




  6. #6
    Registered User
    Join Date
    04-08-2005
    Location
    Washington, DC
    Posts
    63
    Quote Originally Posted by Roger Govier
    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

    >[/color]
    Thanks for the reply...

    Yes I placed it in the General "Module1" Name and it looks like this:
    PHP Code: 
    Function GetName(Optional NameType As String) As String

    Application
    .Volatile

    If Len(NameType) = 0 Then NameType "OFFICE"

    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 
    in the cell if I reference "=GetName(2) i get a #NAME?

    Using Debug I hover over the "Getname =" and I see a " Getname = Error 2015"
    Last edited by swieduwi; 02-02-2006 at 10:36 AM.

  7. #7
    Chip Pearson
    Guest

    Re: Including Environ Username in Cell

    The 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.com


    "swieduwi"
    <[email protected]> wrote in
    message
    news:[email protected]...
    >
    > Roger Govier Wrote:
    >> 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
    >>
    >> >

    > 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 = "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
    >
    > --------------------
    >
    > in the cell I reference "=username()" I get a #REF! in the Cell
    > if I reference "=GetName(2) i get a #NAME?
    >
    >
    > --
    > swieduwi
    > ------------------------------------------------------------------------
    > swieduwi's Profile:
    > http://www.excelforum.com/member.php...o&userid=21962
    > View this thread:
    > http://www.excelforum.com/showthread...hreadid=507221
    >[/color]



  8. #8
    Chip Pearson
    Guest

    Re: Including Environ Username in Cell

    "Roger Govier" <[email protected]> wrote in message

    > 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.com





    "Roger Govier" <[email protected]> wrote in message
    news:%[email protected]...
    > 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"
    > <[email protected]> wrote
    > in message
    > news:[email protected]...
    >>
    >> 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("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
    >>

    >
    >




  9. #9
    Roger Govier
    Guest

    Re: Including Environ Username in Cell

    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 Govier


    "Chip Pearson" <[email protected]> wrote in message
    news:[email protected]...
    > "Roger Govier" <[email protected]> wrote in message
    >
    >> 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.com
    >
    >
    >
    >
    >
    > "Roger Govier" <[email protected]> wrote in message
    > news:%[email protected]...
    >> 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" <[email protected]>
    >> wrote in message
    >> news:[email protected]...
    >>>
    >>> 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("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
    >>>

    >>
    >>

    >
    >




  10. #10
    Registered User
    Join Date
    04-08-2005
    Location
    Washington, DC
    Posts
    63
    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.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1