Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Aug 2004
    Posts
    361
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Environ Function (XP)

    Found this on another site and trying to figure out if it can call a Windows login name into a cell in Excel. If so, how would one go about setting it up in cell B1? I am not sure how functions operate or where they should be placed within code.

    Function UserNameWindows() As String
    UserName = Environ("USERNAME")
    End Function

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Environ Function (XP)

    You could put the code in a module in the workbook:
    - Press Alt+F11 to activate the Visual Basic Editor.
    - Select Insert | Module.
    - Copy the following code into the module (the version you have is not quite correct):
    <code>
    Function UserName() As String
    UserName = Environ("USERNAME")
    End Function
    </code>
    - Switch back to Excel.
    - Enter the following formula in a cell:
    <code>
    =UserName()
    </code>
    If you want the function to be available in all workbooks, you can put it in Personal.xls. See Legare Coleman's Personal.xls Tutorial (All). Functions in Personal.xls can be used as follows in a formula:
    <code>
    =Personal.xls!UserName()</code>

Posting Permissions

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